得到字符串的长度,可以通过maxLength进行一些限制;
username.setSelection(phoneUid.length());
if (scanResult.indexOf("http//") != -1) {
Uri uri = Uri.parse(scanResult);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
Android开发中string.xml文件的使用
android系统后自动在R.java中生成一个引用
public static final class string {
public static final int hello=0x7f040000;
}
这个不用程序员实现。
然后在你代码中需要使用时只需要调用R.string.hello即可.如textView.setText(
string和int互相转化
int i = Integer.parseInt([String]);
int i=12345;
String s=i+"";
pd.setMessage(getString(R.string.Is_the_registered)); 国际化,两套string
pd.setMessage(getResources().getString(R.string.Is_the_registered));
字符串的截取和切割
而"."在正则表达式中属于预定义字符类 表示任何字符(与行结束符可能匹配也可能不匹配)
String [] str="java.java.java".split("\\."); ——需要转义一下!!
for(String s :str){
System.out.println(s);
}
String b=a.substring(0,5);
android开发中怎么将手机号中间四位隐藏,直接用****替换掉中间4位数字
字符串替换就好,把中间的4位数替换成*,然后再显示。
String mobile = "12345671234";
String maskNumber = mobile.substring(0,3)+"****"+mobile.substring(7,mobile.length());
字符串的替换
email 邮箱指定字符串显示星号
String str = "154167891@qq.com";
str.replaceAll(str.substring(4,str.lastIndexOf("@")),"****"));
但是这样从后往前检索的话要是 @ 之前的字符少于4位就有可能出错了。
var reg = /(.{2}).+(.{2}@.+)/g;
var str = "yongliesina1_.23@qq.com";
console.log(str.replace(reg, "$1****$2"));
邮箱的账号加密
采用什么逻辑呢?邮箱的正则式用哪个好呢?
email 邮箱指定字符串显示星号
String str = "154167891@qq.com";
str.replaceAll(str.substring(4,str.lastIndexOf("@")),"****"));
但是这样从后往前检索的话要是 @ 之前的字符少于4位就有可能出错了。
var reg = /(.{2}).+(.{2}@.+)/g;
var str = "yongliesina1_.23@qq.com";
console.log(str.replace(reg, "$1****$2"));
String 与 StringBuffer 用法区别
--当我们进行字符拼接时,请使用StringBuffer类而非String类,因为前者将比后者快上百倍。
的确,在程序的太多场合我们都会进行字符串拼接工作,简单的代码示例如下:
String str="You are nice.";
str+="I love you so much.";
如果用StringBuffer类的话,代码如下:
StringBuffer str= new StringBuffer("You are nice.");
str.append("I love you so much.");
CharSequence和String的区别是什么?
Android 判断字符串是否相等
判断TextView中文字是否相等:
TextView A,B;
if (A.getText().toString.equals(B.getText().toString())) {
//A=B;
}else{
//A!=B;
}
判断TextView是否为空
if( "".equals(A.getText().toString())){
//空
}else{
//非空
}
Java字符串比较大小