1.代码如下:
String strIds = sceneIds.toString();
System.out.println("strIds="+strIds);
int i = strIds.indexOf("[");
int j = strIds.indexOf("]");
System.out.println("i="+i+" j="+j);
if(i != -1 && j != -1){
strIds.replace("[", "(");
strIds.replace("]", ")");
}
System.out.println("strIds="+strIds);
大家来猜下它的结果:
结果是:
strIds=[7, 4, 8, 6, 9, 5]
i=0 j=17
strIds=[7, 4, 8, 6, 9, 5]
2.代码如下(和1有点不一样哦)
String strIds = sceneIds.toString();
System.out.println("strIds="+strIds);
int i = strIds.indexOf("[");
int j = strIds.indexOf("]");
System.out.println("i="+i+" j="+j);
if(i != -1 && j != -1){
strIds = strIds.replace("[", "(");
strIds = strIds.replace("]", ")");
}
System.out.println("strIds="+strIds);
结果如下:
strIds=[7, 4, 8, 6, 9, 5]
i=0 j=17
strIds=(7, 4, 8, 6, 9, 5)
这就是String的replace的奇怪用法!!!!我在这里碰到了两次这样的情况,以后一定要谨记!!!!
分享到:
相关推荐
delphi 自带 StringReplace 慢, 替换 StringReplace ,高效率,秒杀 原版
Delphi自带的StringReplace效率非常低,字符串长一些就很慢。这个速度绝对快,你可以和StringReplace比一下,
C++ 标准库string replace成员的几个用法
Arduino项目开发 Strings_StringReplace_StringReplace.pdf 学习资料 复习资料 教学资源
WPF中StringFormat的用法可以参照C#中string.Format的用法
String的基本用法
String.replace( ) 简介 语法: 代码如下: string.replace(regexp, replacement) regexp :您要执行替换操作的正则... String.replace( ) 的简单用法 代码如下: var text = “javascript 非常强大 !”; text.repl
c++中stringstream的用法 istringstream, ostringstream, stringstream用法示例
详细的string类用法总结,各种函数都有
C#_StringList的用法,这个对于学C#_StringList的用法有一些帮组的。
StringReader的用法---马克-to-win java视频字符串输入流的介绍
replace方法是javascript涉及到正则表达式中较为复杂的一个方法,严格上说应该是string对象的方法。只不过牵扯到正则的时候比较多一些。需要我们灵活的使用。 语法: stringObj.replace(regexp/substr,replacement)...
介绍C++中string类的基本用法以及与C语言的比较,简单明了适合初学者。
介绍了C#中String字符串类型的各种用法,各种字符串的格式。
string.Format 的多种用法,希望可以帮助其他人!
代码如下:[ThreadStatic] static char[] mTempChars; protected static char[] GetTempData() { if (mTempChars == null) mTempChars = ... } public static string Replace(string value, string oldData, stri
string的用法 string的用法 string的用法 string的用法
java String.format用法
$ npm install --save react-string-replace 用法 简单的例子 const reactStringReplace = require ( 'react-string-replace' ) reactStringReplace ( 'whats your name' , 'your' , ( match , i ) => ( < span> { ...