stringuse.txt

来自「StringUse.java 实现了一个串操作的实例。」· 文本 代码 · 共 42 行

TXT
42
字号
/*Source*/
public class StringUse{
    public static void main(String[] args){
        String s1 = new String("fantacy");
        char c[]=new char[10];
        s1.getChars(0,3,c,0);
        System.out.println("s1.length = "+s1.length());
        System.out.print("s1.startWith fan = ");
        System.out.println(s1.startsWith("fan"));
        System.out.print("s1.endWith fan = ");
        System.out.println(s1.endsWith("fan"));
        System.out.println("s1.charAt(4)="+s1.charAt(4));

        

	String sql = "select x from x where id=x";
	System.out.println("before is:"+sql);
	String r1 = sql.replace("x", "table");
	System.out.println("replace:" + r1);
	String r2 = sql.replaceFirst("x", "table");
	System.out.println("replaceFirst:" + r2);
	String r3 = sql.replaceAll("x", "table");
	System.out.println("replaceAll:" + r3);

    }
}


/*Result
--------------------Configuration: <Default>--------------------
s1.length = 7
s1.startWith fan = true
s1.endWith fan = false
s1.charAt(4)=a
before is:select x from x where id=x
replace:select table from table where id=table
replaceFirst:select table from x where id=x
replaceAll:select table from table where id=table

Process completed.

*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?