社区
Java EE
帖子详情
indexof(int int);
luck5
2005-07-11 10:10:16
使用indexOf(int);和indexOf(int,int)这两中方法怎么都返回-1,
String str="a2sdfdcdsfsdfsdfa";
System.out.println( str.indexOf(3));
System.out.println( str.indexOf(1,2));
...全文
410
19
打赏
收藏
indexof(int int);
使用indexOf(int);和indexOf(int,int)这两中方法怎么都返回-1, String str="a2sdfdcdsfsdfsdfa"; System.out.println( str.indexOf(3)); System.out.println( str.indexOf(1,2));
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
19 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
wangw1319
2005-07-12
打赏
举报
回复
我来做一下小该动::
int ch=str.charAt(0);
System.out.print(ch);
这样就OK了
yyzh
2005-07-12
打赏
举报
回复
我的是1.4.2_08-b03
luck5
2005-07-12
打赏
举报
回复
啊,怎么可能:我的是1.4.2
ses127127
2005-07-12
打赏
举报
回复
楼上的回答很好
wangw1319
2005-07-12
打赏
举报
回复
我也试过,打印出来的结果是不一样的!可能他的JDK版本低于1.4的吧!
luck5
2005-07-12
打赏
举报
回复
楼上果然变通的好
luck5
2005-07-11
打赏
举报
回复
不是啊,
String str="bbc";
System.out.print(str.charAt(0));
结果明明是
b
ChDw
2005-07-11
打赏
举报
回复
charAt(index)就是返回它的ascii码的
luck5
2005-07-11
打赏
举报
回复
这个问题我明白拉:
没有函数可以将一个字符转成acsii吗
wangw1319
2005-07-11
打赏
举报
回复
不用转换
wangw1319
2005-07-11
打赏
举报
回复
楼上的答案已经够清晰了,应该明白了吧!
luck5
2005-07-11
打赏
举报
回复
哦,原来(int)是取acsii啊:)
还有,哪个函数将字付换成acsii?
yyzh
2005-07-11
打赏
举报
回复
如果是截取字符串,应该是这样
str.substring(3);
str.substring(1,3);
str.charAt(0);是取得字符串第一位的acsii码,取得结果是a=97
然后再
System.out.println(str.indexOf(97)); 会得到0;
humanity
2005-07-11
打赏
举报
回复
当然了, 你找 ASCII 码为 3 对应的字符,明显没有嘛, 当然 -1,
你又从位置2开始找 ASCII 码为 1 的字符, 当然也没有.
注意这里第一个参数 , 是一个能对应到字符的整数, 比如 ASCII ,
kaoziji
2005-07-11
打赏
举报
回复
没有错啊!
在你的str字符串中,acsii为3的字符确实不存在啊
acsii为1的字符也不存在
yyzh
2005-07-11
打赏
举报
回复
我测了一下
char ch=str.charAt(0);
System.out.print(ch);
和
System.out.print(str.charAt(0));
在我这打印出来的结果是不一样的。
你那里是什么版本的JDK?我不清楚不同版本的JDK会不会有这个差异!
luck5
2005-07-11
打赏
举报
回复
不知道yyzh(顶楼的千万记得结贴给分) 有没有测试一下,怎么我
char ch=str.charAt(0);
System.out.print(ch);
和
System.out.print(str.charAt(0));
打出来的都是
b
wangw1319
2005-07-11
打赏
举报
回复
楼上说的好!
yyzh
2005-07-11
打赏
举报
回复
楼主是被System.out.print愚弄了。
首先str.charAt(0) 返回值是 char型的。
Char型变量存储一个字符,因为Java使用Unicode,所以每个字符16位 两个字节。
可以这样负值--
char ch=0;
char ch='X'
char ch='\u0058'
所以 如果这样
String str="bbc";
char ch=str.charAt(0);
System.out.print(ch);
打印出的是'b'的ascii编码
如果System.out.print(str.charAt(0));
打印出的是字符串
--------
好像还是没说明白,总之 你看一下 System.out.println 中println()的代码就清楚了,一层层的看下去
基于Web的酒店客房管理系统的设计与实现+论文+开题
mineSave(Model model,HttpServletRequest request,Long id ,String username,String password,String name,String gh,String mobile) throws Exception{
int
result = 0; String sql="update t_user set name=?,gh...
int
indexOf
(
int
ch,
int
fromIndex)函数
int
indexOf
(
int
ch,
int
fromIndex)函数:就是字符ch在字串fromindex位后出现的第一个位置.没有找到返加-1eg:String str=”a2dfcfar1bzvb”;System.out.pr
int
ln(str.
indexOf
(97,2));看这个例子,输出:6a的ASCII为...
Java字符串
indexOf
(
int
ch,
int
fromIndex)方法,带示例
字符串
indexOf
(
int
ch,
int
fromIndex)方法 (String
indexOf
(
int
ch,
int
fromIndex) Method)
indexOf
(
int
ch,
int
fromIndex) is a String method in Java and it is used to get the index of a specified ...
JAVA String方法中public
int
indexOf
(
int
ch)问题
int
indexOf
(
int
ch) //返回指定字符在此字符串中第一次出现处的索引。
int
indexOf
(
int
ch,
int
fromIndex) //返回在此字符串中第一次出现指定字符处的索引,从指定的索引开始搜索。
int
indexOf
(Strin
indexof
java_Java中
indexOf
的用法
indexOf
有四种用法:1.
indexOf
(
int
ch) 在给定字符串中查找字符(ASCII),找到返回字符数组所对应的下标找不到返回-12.
indexOf
(String str)在给定符串中查找另一个字符串。。。3.
indexOf
(
int
ch,
int
fromIndex)从指定...
Java EE
67,515
社区成员
225,878
社区内容
发帖
与我相关
我的任务
Java EE
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
复制链接
扫一扫
分享
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章