Tell me about split friends

I have two questions.

The first question is how to use splits in duplicate ??
If the variable name is a1, is it possible to write a1.split ("@“C) .last and then use “-” and split again for the values ​​in it? a1.split (”@"C) .last.split ( ”- "C) I get an error when I write .first like this.

The second question is a1.split(“@”.ToCharArray) (3) If you do this, I think the 4th value should come from the values ​​divided by @ among the variables of a1. However, if you print on the write line, an empty value is output.

Hello,

for the first question, if you are using all the string in one shot you have to convert the Object coming out from last with ToString, otherwise the second split will not work.

This
image

with a1 = “a-b-c@d-e-f@g-h-i” correctly returns g

For the second question you are right, the index is zero-based so (3) will return the 4th value.
For example with “a-b-c@d-e-f@g-h-i@j-k-l@m-n-o” it returns “j-k-l”
If the returned value is empty check if it’s not the last character after @ (so if the format is not “@…@”) or store all the array and check manually which is the fourth value.

3 Likes

Thank you for your help, good luck friends!!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.