java替换字符串和用indexof查找字符
java自带替换
String s="hlz_and_hourui哈哈";
String new_S=s.replaceAll("哈", "笑毛");
System.out.println(new_S);
则输出为:"hlz_and_hourui笑毛笑毛";
package find_repalce_keywords; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader; public class find_repalce_keywords { public static void main(String[] args) { String s="hlz_and_hourui哈哈";
//java自带替换
String new_S=s.replaceAll("哈", "笑毛");
System.out.println(new_S);
String input = null;
String finding=null;
System.out.println("enter a string:");
System.out.flush(); try {
input=getString();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("输入你想查找的词");
try {
finding=getString();
} catch (IOException e) {
e.printStackTrace();
}
FindAndRepace far=new FindAndRepace();
far.repalce(input, finding); } //I/O操作
public static String getString() throws IOException {
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String s=br.readLine();
return s;
}
} class FindAndRepace
{
int i=0;
public int repalce(String str,String finding)
{
if(str.indexOf(finding, i)!=-1)
{ System.out.print("要找的"+finding+"在"+(str.indexOf(finding, i)+1)+"||||");
i=str.indexOf(finding, i)+1;
repalce(str, finding);//递归
}
else
{
System.out.println("搜索结束");
}
return i;
} }
运行效果:

java替换字符串和用indexof查找字符的更多相关文章
- 【转】Java中字符串中子串的查找共有四种方法(indexof())
原文网址:http://wfly2004.blog.163.com/blog/static/1176427201032692927349/ Java中字符串中子串的查找共有四种方法,如下:1.int ...
- Java中字符串中子串的查找共有四种方法(indexof())
Java中字符串中子串的查找共有四种方法(indexof()) Java中字符串中子串的查找共有四种方法,如下:1.int indexOf(String str) :返回第一次出现的指定子字符串在此字 ...
- java 替换字符串模板(模板渲染)
java渲染字符串模板,也就是说在java字符串模板中设置变量字符串,使用变量去渲染指定模板中设置好的变量字符串.下面介绍4种替换模板方式: 1.使用内置String.format String me ...
- 经历:Java中字符串中按照多个字符拆分或替换:split()和replaceAll()
一.replaceAll() 今天,遇到了这样的一个字符串[如下代码]: String s="@0|新港@0|天津@0|东莞@0|南沙@0|营口@0|钦州@0|上海@0|汕头@0|连云港@0 ...
- js替换字符串中所有指定的字符
第一次发现JavaScript中replace() 方法如果直接用str.replace("-","!") 只会替换第一个匹配的字符. 而str.replac ...
- Java替换字符串中的占位符
在开发中,会有动态配置字符串其中的某些字符,如何使用字符中的占位符,并且在代码动态替换占位符实现动态配置字符串! 1.定义字符串时,再string文件添加字符串: 注意!记得要在字符文件中加上这些: ...
- java:替换字符串中的ASCII码
可对照查看网盘ASCII表http://yunpan.cn/cyxg4wQjQaGEQ (提取码:8b29) public static void main(String[] args) { // / ...
- java替换字符串中的World为Money
public class Money{ public static void main(String[] args) { String a = "Hello Java World\n&quo ...
- java 统计字符串中连续重复的字符,并得出新字符串
题目: 比如输入为aaabbc,输出a3b2c1 完整解答: public class Other { static String func(String str) { StringBuffer re ...
随机推荐
- 前端--关于javascript函数
终于可以说说函数了,函数是javascript设计最出色的地方,可以说它是所有概念中最重要的一个,因为围绕函数而阐述的周边概念涵盖了javascript的方方面面,所以理解了函数可以说对javascr ...
- (转载)Windows下手动完全卸载Oracle
使用Oracle自带的Universal Installer卸载存在问题: 不干净,不完全,还有一些注册表残留,会影响到后来的安装. 所以,推荐使用手工卸载Oracle. 1.[win+R]-> ...
- sqlcommand循环内使用
using (SqlConnection conn = new SqlConnection()) { SqlCommand comm= new SqlCommand(); conn.Connectio ...
- codeforces 339C Xenia and Bit Operations(线段树水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Xenia and Bit Operations Xenia the beginn ...
- Orchard开源ASP.NET MVC CMS简介
项目简介: Orchard CMS 是一个免费的开放源代码内容管理系统,让用户可在 Microsoft ASP.NET MVC 平台上快速创建网站.它基于灵活的扩展性框架构建,使开发人员和定制人员可通 ...
- PHP遍历文件夹下的文件和获取到input name的值
<?php$dir = dirname(__FILE__); //要遍历的目录名字 ->当前文件所在的文件夹//$dir='D:\PHP\wamp\www\admin\hosts\admi ...
- IIS6.0架构概览(翻译)
IIS6.0提供一个重新设计的万维网发布服务(World Wide Web Publishing Service)架构,可以帮助你为你的网站构建更好的性能.可靠.可扩展性(scalability),无 ...
- 无法添加sql server ER图
Database diagram support objects cannot be installed because this database does not have a valid own ...
- Redis Clients Handling
This document provides information about how Redis handles clients from the point of view of the net ...
- Roy the Robber
Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that th ...