Segmentation of strings in Java

Code and renderings

String segmentation

The code is as follows (example):

public class Hello4 {
    
    
    public static void main(String[] args) {
    
    
        String name="张三,18,开发部,湖北武汉软件园";
        String[] xingming=name.split(",");
        System.out.println(name);
        System.out.println("把字符串中的张三改成李四:");
        for (int i = 0; i <xingming.length ; i++) {
    
    
            if (i==0){
    
    
                xingming[i]="李四";
            }
            System.out.print(xingming[i]+"\t");
        }
    }
}

Insert picture description here

to sum up

The above is the segmentation content of the string, which is mainly used to form an array after the segmentation of the string, so as to realize the modification of the string content.

Guess you like

Origin blog.csdn.net/StruggleBamboo/article/details/110671631