文字列系
indexOf(String str, int fromIndex)
指定されたfromIndex以降でstrが最初に出てくる位置のインデックスを返す
見つからなかったら-1がかえってくる。
例)
String csv = "aaa,b,cccc,d";
int index = csv.indexOf(",",5);
int indexには6がはいる。
substring(int beginIndex, int endIndex)
beginIndexからendIndex -1 までの文字列をとってくる
例)
String str = "hambuger".substring(4, 8);
strには"urge"が入る
lastIndexOf(String str)
指定されたstrが文字列中の一番最後に出てくる位置を返す
見つからなかったら-1がかえってくる。
例)
String csv = "aaa,b,ccc,d,ccc,f";
int lastIndex = csv.lastIndexOf("ccc");
lastIndex には12が入る。
replaceAll(String regex, String replacement)
regexに該当する文字列を、replacementに置換する
例)
String before = "asami_asami.asami!asami";
String after = replaceAll(".asami", ".chocolate");
afterは"asami_asami.chocolate!asami"になる。
例)J2SE 1.4.xでは
String after = replaceAll("\\Q" + ".asami" + "\\E", ".chocolate");
にしなきゃだめ。
MessageFormat.format(String pattern, Object arguments)
指定されたパターンを使って MessageFormat を作成し、それを使用して指定された引数をフォーマットします
例)
String st1 = "abc{0}";
String st2 = "def";
System.out.println(MessageFormat.format(st1, st2);
結果)
abcdef
合計: -
最終更新:2011年10月17日 14:09