class CheckString {
public static void main(String[] arguments) {
String str = "Nobody ever went broke by buying IBM";
System.out.println("The string is: " + str);
System.out.println("Length of this string: "
+ str.length());
System.out.println("The character at position 5: "
+ str.charAt(5));
System.out.println("The substring from 26 to 32: "
+ str.substring(26, 32));
System.out.println("The index of the character v: "
+ str.indexOf('v'));
System.out.println("The index of the beginning of the "
+ "substring \"IBM\": " + str.indexOf("IBM"));
System.out.println("The string in upper case: "
+ str.toUpperCase());
}
}
The string is: Nobody ever went broke by buying IBM
Length of this string: 36
The character at position 5: y
The substring from 26 to 32: buying
The index of the character v: 8
The index of the beginning of the substring "IBM": 33
The string in upper case: NOBODY EVER WENT BROKE BY BUYING IBM
Press any key to continue . . .
我的问题是我substring() indexof() toUpperCase() 这些字符串位置是不是都是从0开始啊?
public static void main(String[] arguments) {
String str = "Nobody ever went broke by buying IBM";
System.out.println("The string is: " + str);
System.out.println("Length of this string: "
+ str.length());
System.out.println("The character at position 5: "
+ str.charAt(5));
System.out.println("The substring from 26 to 32: "
+ str.substring(26, 32));
System.out.println("The index of the character v: "
+ str.indexOf('v'));
System.out.println("The index of the beginning of the "
+ "substring \"IBM\": " + str.indexOf("IBM"));
System.out.println("The string in upper case: "
+ str.toUpperCase());
}
}
The string is: Nobody ever went broke by buying IBM
Length of this string: 36
The character at position 5: y
The substring from 26 to 32: buying
The index of the character v: 8
The index of the beginning of the substring "IBM": 33
The string in upper case: NOBODY EVER WENT BROKE BY BUYING IBM
Press any key to continue . . .
我的问题是我substring() indexof() toUpperCase() 这些字符串位置是不是都是从0开始啊?
解决方案 »
- [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
- 按钮选择事件:将自己删除
- Eclipse问题
- 如何在具有GUI界面的java程序中退出时自动启动浏览器并且访问某一个特定网址?
- 混合字符串(中英混合)的分割问题!!急!!解决马上结帐
- 我是JBUILDER9.0的初学者想求一个学习的网站 谢谢 在线等待!!!
- Daemon线程是什么?在实际工作中用得多不?
- 为什么我的程序老是提示出错?
- 除了weblgoic,我们能用其它的应用服务器吗?
- 进者有分!!!!!
- 请问 java 有没有 数据集 关联 的 表格控件 ? 还有没有 像delphi 的 cxgrid和 dbgridEh 那样的 表格控件 ?
- 帮忙看看这2句是啥意思!
int endIndex) 返回一个新字符串,它是此字符串的一个子字符串。该子字符串从指定的 beginIndex 处开始,直到索引 endIndex - 1 处的字符。因此,该子字符串的长度为 endIndex-beginIndex。 示例: "hamburger".substring(4, 8) returns "urge" "smiles".substring(1, 5) returns "mile" 参数:
beginIndex - 起始索引(包括)。
endIndex - 结束索引(不包括)。
返回:
指定的子字符串。
抛出:
IndexOutOfBoundsException - 如果 beginIndex 为负,或 endIndex 大于此 String 对象的长度,或 beginIndex 大于 endIndex。
int fromIndex) 返回指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始。返回的整数是满足下式的最小 k 值: k >= Math.min(fromIndex, this.length()) && this.startsWith(str, k) 如果不存在这样的 k 值,则返回 -1。 参数:
str - 要搜索的子字符串。
fromIndex - 开始搜索的索引位置。
返回:
指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始。
要转换为大写的 String。
另请参见:
toUpperCase(Locale)