Android TextUtils类常用方法

Log.d(TAG, "---------------------------------");
        //字符串拼接
        Log.d(TAG, TextUtils.concat("Hello", " ", "world!").toString());
        //判断是否为空字符串
        Log.d(TAG, TextUtils.isEmpty("Hello") + "");
        //判断是否只有数字
        Log.d(TAG, TextUtils.isDigitsOnly("Hello") + "");
        //判断字符串是否相等
        Log.d(TAG, TextUtils.equals("Hello", "Hello") + "");
        //获取字符串的倒序
        Log.d(TAG, TextUtils.getReverse("Hello", 0, "Hello".length()).toString());
        //获取字符串的长度
        Log.d(TAG, TextUtils.getTrimmedLength("Hello world!") + "");
        Log.d(TAG, TextUtils.getTrimmedLength("  Hello world!  ") + "");
        //获取html格式的字符串
        Log.d(TAG, TextUtils.htmlEncode("\n" +
                "\n" +
                "这是一个非常简单的HTML。\n" +
                "\n" +
                ""));
        //获取字符串中第一次出现子字符串的字符位置
        Log.d(TAG, TextUtils.indexOf("Hello world!", "Hello") + "");
        //截取字符串
        Log.d(TAG, TextUtils.substring("Hello world!", 0, 5));
        //通过表达式截取字符串
        Log.d(TAG, TextUtils.split("  Hello world!  ", " ")[0]);

你可能感兴趣的:(Android实例教程)