String 類別 (class) 有 subString() 方法 (method)。
subString可由一個字串取出一個子字串。
public class Test { public static void main(String[] args){ String text = "To be or not to be, that is the question;"+ " Whether 'tis nobler in the mind to suffer"+ " the slings and arrows of outrageous fortune,"+ " or to take arms against a sea of troubles," + " and by opposing end them?"; String sub1 = text.substring(171); String sub2 = text.substring(20, 41); System.out.println(sub1); System.out.println(sub2); } }
沒有留言:
張貼留言