[How to intercept the string in front of @ in java]

How to intercept in java based on the @ character and get the string in front of @

  Use substring to intercept, get the index value of the @ character, and intercept the index value from 0 to @. You can get the string in front of @

public class Test {
    
    
    public static void main(String[] args) {
    
    
        String email = "[email protected]";
        System.out.println(email);
        //indexOf("@")----获取@字符索引值
        String emailPrefix = email.substring(0, email.indexOf("@"));
        System.out.println(emailPrefix);
    }
}

  Print the result:
Insert image description here

Guess you like

Origin blog.csdn.net/qq_45278500/article/details/126848369