發表文章

目前顯示的是 7月, 2019的文章

[Java] String 轉換 Integer

String -> Integer //將 String 轉換成 Integer public static void main(String[] args) { String str = "1234"; int intValue1 = Integer.parseInt(str); int intValue2 = Integer.parseInt("12345"); int intValue3 = Integer.valueOf("12345"); } Integer -> String //將 Integer 轉換成 String public static void main(String[] args) { int intValue = "1234"; String str1 = String.valueOf(intValue); String str2 = Integer.toString(intValue); String str3 = "" + intValue; } By Hao★

[Java] replace()、trim()

replace( ) 取代 Code: public static void main(String[] args) { String s1 = "ABC123ABC123"; String s2 = "ABC 123"; String s3 = "ABC_123"; System.out.println(s1.replace("ABC","abc")); // System.out.println(s1); System.out.println(s2.replace(" ","")); System.out.println(s3.replace("_"," ")); } 輸出: abc123abc123 ABC123 ABC 123 ABC123ABC123 trim( ) 去掉頭尾空白字元 Code: public static void main(String[] args) { String s1 = " 123 "; String s2 = " abc 123 "; System.out.println(s1. trim()); System.out.println(s2. trim()); //只會去掉前後的空白 } 輸出: 123 abc 123 By Hao★

[Java] indexOf()、lastIndexOf()

indexOf( ) Code: public static void main(String[] args) { String s1 = "ABCDEFG"; if(s1.indexOf("CDE")) //s1.indexOf("CDE") = 2 System.out.println("CDE is located at index 2"); if(s1.indexOf("Test") < 0) //s1.indexOf("Test") = -1 System.out.println("s1 not contain Test"); } 輸出: CDE is located at index 2 s1 not contain Test lastIndexOf( )  Code: public static void main(String[] args) { String s1 = "ABCDEFG_ABCDEFG"; if(s1.lastIndexOf("CDE")) //s1.lastIndexOf("CDE") = 10 System.out.println("CDE is located at index 10"); if(s1.lastIndexOf("Test") >= 0) //s1.lastIndexOf("Test") = -1 System.out.println("s1 not contain Test"); } 輸出: CDE is located at index 10 By Hao★

[Java] startsWith()、endsWith()

startsWith( ) Code: public static void main(String[] args) { String s1 = "Hello World"; if(s1.startsWith("Hello")) System.out.println("s1 starts with Hello"); if(s1.startsWith("W",6)) System.out.println("s1 starts with W at position 6"); } 輸出: s1 starts with Hello endsWith( )  Code: public static void main(String[] args) { String s1 = "Hello World"; if(s1.endsWith("World")) System.out.println("s1 ends with World"); } 輸出: s1 ends with World By Hao★

[Java] equals()、equalsIgnoreCase()

equals( ) Code: public static void main(String[] args) { String s1 = "hello"; if(s1.equals("hello")) System.out.println("s1 equals hello"); else System.out.println("s1 not equals hello"); } 輸出: s1 equals hello equalsIgnoreCase( )  Code: public static void main(String[] args) { String s1 = "hello"; String s2 = "Hello"; if(s1.equalsIgnoreCase(s2)) System.out.println("s1 equals s2"); else System.out.println("s1 not equals s2"); } //equalsIgnoreCase會忽略大小寫 輸出: s1 equals s2 By Hao★

[Linux] 執行Shell Script

設定執行權  開啟user/group/other三者的執行權限   chmod +x test.sh  如果需要只為某些使用者開權限可以用   chmod u+x test.sh #user   chmod g+x test.sh #group   chmod o+x test.sh #other  如果需要關掉權限   chmod -x test.sh 執行Shell 執行現在目錄下的Shell ./test.sh 讓Shell在背景執行 ./test.sh & 一一一一一一一一一一 $ ./test.sh & [1] 10182 [1]+ Done       ./test.sh 一一一一一一一一一一 顯示Shell中執行的步驟 csh -x test.sh bash -x test.sh By Hao★