Search code examples
fluttersubstring

flutter : how to substring string from last of special character like @


I have this string ffff @fgggg @, How can I do substring last @, Thats mean When I am using this code:

String text =  `ffff @fgggg @`;
selectedUser = text.substring();

I expect selectedUser be == "";

I want to check text from last @ ? If after last @ be nothing, substring() method return "" ?


Solution

  • I found answer :

     selectedUser = text.substring(text.lastIndexOf('@') + 1);
    

    and I got "". It checked from last @.