문자열을 두 부분으로 분리하고 두 개의 다른 변수에 저장할 수있는 방법을 알고 싶었습니다. 당신은 String
의 split
방법을 사용할 수 있습니다문자열을 정수와 구분하여 저장하는 방법
String part1 = "3";
String part2 = "abc";
, 감사
문자열을 두 부분으로 분리하고 두 개의 다른 변수에 저장할 수있는 방법을 알고 싶었습니다. 당신은 String
의 split
방법을 사용할 수 있습니다문자열을 정수와 구분하여 저장하는 방법
String part1 = "3";
String part2 = "abc";
, 감사
String[] strArray = str.split("-");
String part1=strArray[0];
String part2=strArray[1];
을 :
String str = "3-abc";
를 그리고 두 개의 문자열에 저장하려면 :
나는이 수업. 그래서
String[] parts = str.split("-");
String part1 = parts[0];
String part2 = parts[1];
Splits this string around matches of the given regular expression.
Returns:
the array of strings computed by splitting this string around
matches of the given regular expression
당신은 분할 기능
String[] temp;
String delimiter = "-";
temp = str.split(delimter);
for(int i =0; i < temp.length ; i++)
System.out.println(temp[i]);
를 사용할 수있는 문자열은 모두 하나의 형식으로 당신은 변환하려고 그 후 String[] splittedStrings = str.split("-");
를 사용하는 경우 문자열을 정수로 Integer.parseInt(splittedStrings[0]);
[정규 표현식] (http://docs.oracle.com/javase/tutorial/essential/regex/)을 사용하십시오. – Xaerxess