首页 文章 精选 留言 我的

精选列表

搜索[字符串],共10003篇文章
优秀的个人博客,低调大师

Java 字符串 之 字符串 记事本实例

http://www.verejava.com/?id=17159658585531 import java.util.Scanner; public class Test { private Scanner in; private StringBuffer sb = new StringBuffer(); private boolean flag = true; private String clipBoard;//剪贴板 public Test() { in = new Scanner(System.in); System.out.println("1 : 键盘输入编辑文字"); System.out.println("2 : 追加文字"); System.out.println("3 : 插入文字 (索引号:要插入的文字)"); System.out.println("4 : 替换文字 (要替换的文字:新文字)"); System.out.println("5 : 查找文字(返回找到的文字的索引号)"); System.out.println("6 : 删除文字(开始索引号:结束索引号)"); System.out.println("7 : 复制文字 (开始索引号:结束索引号)"); System.out.println("8 : 粘贴文字(索引号)"); System.out.println("9 : 剪切文字(开始索引号:结束索引号)"); System.out.println("10 : 转换成大写"); System.out.println("11 : 转换成小写"); System.out.println("12 : 文字反转"); System.out.println("-1 : 退出编辑"); while (flag) { String key = in.nextLine(); if ("1".equals(key)) { input(); } if ("-1".equals(key)) { exit(); } if ("2".equals(key)) { append(); } if ("3".equals(key)) { insert(); } if ("4".equals(key)) { replace(); } if ("5".equals(key)) { search(); } if ("6".equals(key)) { delete(); } if ("7".equals(key)) { copy(); } if ("8".equals(key)) { paste(); } if ("9".equals(key)) { cut(); } if ("10".equals(key)) { toUpperCase(); } if ("11".equals(key)) { toLowerCase(); } if ("12".equals(key)) { rerverse(); } System.out.println("记事本当前文本:" + sb.toString()); } } private void rerverse() { sb.reverse(); } private void toLowerCase() { String buffer = sb.toString(); buffer = buffer.toLowerCase(); sb.delete(0, sb.length()); sb.append(buffer); } private void toUpperCase() { String buffer = sb.toString(); buffer = buffer.toUpperCase(); sb.delete(0, sb.length()); sb.append(buffer); } private void cut() { System.out.println("请输入要剪切文字(开始索引号:结束索引号)"); String text = in.nextLine(); String[] texts = text.split(":"); int startIndex = Integer.parseInt(texts[0]); int endIndex = Integer.parseInt(texts[1]); clipBoard = sb.substring(startIndex, endIndex); //删除记事本文字 sb.delete(startIndex, endIndex); } private void paste() { System.out.println("请输入要粘贴文字(索引号)"); String text = in.nextLine(); int index = Integer.parseInt(text); //粘贴 sb.insert(index, clipBoard); } private void copy() { System.out.println("请输入要复制文字 (开始索引号:结束索引号)"); String text = in.nextLine(); String[] texts = text.split(":"); int startIndex = Integer.parseInt(texts[0]); int endIndex = Integer.parseInt(texts[1]); clipBoard = sb.substring(startIndex, endIndex); } private void delete() { System.out.println("请输入要删除文字(开始索引号:结束索引号)"); String text = in.nextLine(); String[] texts = text.split(":"); int startIndex = Integer.parseInt(texts[0]); int endIndex = Integer.parseInt(texts[1]); //删除 sb.delete(startIndex, endIndex); } private void search() { System.out.println("请输入要查找文字(返回找到的文字的索引号)"); String text = in.nextLine(); int index = sb.indexOf(text); if (index >= 0) { System.out.println(text + " 索引号:" + index); } else { System.out.println(text + " 不存在"); } } private void replace() { System.out.println("请输入要替换文字 (要替换的文字:新文字)"); String text = in.nextLine(); String[] texts = text.split(":"); String oldText = texts[0]; String newText = texts[1]; //替换 String buffer = sb.toString(); buffer = buffer.replace(oldText, newText); sb.delete(0, sb.length());//清空记事本文字 sb.append(buffer); } private void insert() { System.out.println("请输入要插入的文字: (索引号:要插入的文字)"); String text = in.nextLine(); String[] texts = text.split(":"); int index = Integer.parseInt(texts[0]); String str = texts[1]; //插入文字 sb.insert(index, str); } private void append() { System.out.println("请输入要追加文字:"); String text = in.nextLine(); //追加文字 sb.append(text); } private void exit() { flag = false; System.exit(0);//退出应用程序 } private void input() { System.out.println("请输入要编辑的文字:"); String text = in.nextLine(); //添加到 sb 记事本的缓冲区 sb.append(text); } public static void main(String[] args) { new Test(); } } http://www.verejava.com/?id=17159658585531

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册