android String.charAt的使用
2017-10-13 08:26
288 查看
今天,简单讲讲String里的
charAt()的使用。
描述
java.lang.String.charAt() 方法返回指定索引处的char值。索引范围是从0到length() - 1。对于数组索引,序列的第一个char值是在索引为0,索引1,依此类推,
以下是声明java.lang.String.charAt()方法
index -- 这是该指数的char值.
此方法返回这个字符串的指定索引处的char值。第一个char值的索引为0.
IndexOutOfBoundsException -- 如果index参数为负或不小于该字符串的长度.
下面的示例演示使用的java.lang.String.charAt()方法.
让我们编译和运行上面的程序,这将产生以下结果。它也会打印空白字符。
这个实在太简单了,其实使用String.subString(i,i+1)也可以实现同样的效果。
android String.charAt的使用就讲完了。
就这么简单。
charAt()的使用。
描述
java.lang.String.charAt() 方法返回指定索引处的char值。索引范围是从0到length() - 1。对于数组索引,序列的第一个char值是在索引为0,索引1,依此类推,
声明
以下是声明java.lang.String.charAt()方法public char charAt(int index)
参数
index -- 这是该指数的char值.
返回值
此方法返回这个字符串的指定索引处的char值。第一个char值的索引为0.
异常
IndexOutOfBoundsException -- 如果index参数为负或不小于该字符串的长度.
实例
下面的示例演示使用的java.lang.String.charAt()方法.package com.yiibai; import java.lang.*; public class StringDemo { public static void main(String[] args) { String str = "This is yiibai"; // prints character at 1st location System.out.println(str.charAt(0)); // prints character at 5th location i.e white-space character System.out.println(str.charAt(4)); // prints character at 18th location System.out.println(str.charAt(17)); } }
让我们编译和运行上面的程序,这将产生以下结果。它也会打印空白字符。
T p
这个实在太简单了,其实使用String.subString(i,i+1)也可以实现同样的效果。
android String.charAt的使用就讲完了。
就这么简单。
相关文章推荐
- Android中string.xml使用总结
- Android,string.xml中使用占位符
- Android的string.xml中使用html与变量
- android中string.xml文件的使用
- android中string.xml文件的使用
- String android.content.Context.getString(int resId, Object... formatArgs)的使用
- android在程序代码中使用String资源
- Android中string.xml使用总结
- Android string.xml中使用html标签
- Android的string-array数据源简单使用
- 我的Android进阶之旅------>Android中可替换string的使用,getString(int resId, Object... formatArgs)
- 【总结】关于在Android中如何使用字符串数组String[]
- android SpannableString使用详解
- Android开发中string.xml文件的使用
- Android String资源文件的使用
- Android 编程下string-array 的使用
- Android中string.xml使用总结
- android中string.xml文件的使用
- Android的string-array数据源简单使用
- Android的string-array数据源简单使用