분할 정규 표현식입니다
import java.util.Scanner;
public class Substring{
public static void main(String[]args){
Scanner user_input = new Scanner(System.in);
String fullname = ""; //declaring a variable so the user can enter their full name
String[] NameSplit = new String[2];
String FirstName;
String MiddleName;
String LastName;
System.out.println("Enter your full name (First Middle Last): ");
fullname = user_input.next(); //saving the user's name in the string fullname
NameSplit = fullname.split(" ");//We are splitting up the value of fullname every time there is a space between words
FirstName = NameSplit[0]; //Putting the values that are in the array into seperate string values, so they are easier to handle
MiddleName = NameSplit[1];
LastName = NameSplit[2];
System.out.println(fullname); //outputting the user's orginal input
System.out.println(LastName+ ", "+ FirstName +" "+ MiddleName);//outputting the last name first, then the first name, then the middle name
new StringBuilder(FirstName).reverse().toString();
System.out.println(FirstName);
}
을} 필요한 경우 여기 내 코드, 당신은 하나 이상의 공백도 찾아보실 수 있습니다 ("+") 대신에 하나의 공간 ("").
String[] array = s.split(" +");
또는 당신은 다음과 같은 장소에서 Strint 토크 나이
String message = "MY name is ";
String delim = " \n\r\t,.;"; //insert here all delimitators
StringTokenizer st = new StringTokenizer(message,delim);
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
왜이다 fullname.split ("") 대신 fullname.split ("\\")을 수행 하시겠습니까? 임 확실히 전에 내가 이것을 해 봤고 효과가 있었다. – Addi
그래,하지만 네가 뭘했는지 우리에게 말하지 않았어. 그러니까 .. –
그럴 수는 없어. 내 잘못은 –