Hi
I’m trying split a string, but I have a error message. What is it wrong?
//Split
string n_s = "John_Smith";
string name = "";
void Start () {
//Split
string[] splitArray = n_s.Split(n_s,char.Parse("_")); //Here we assing the splitted string to array by that char
name = splitArray[0]; //Here we assign the first part to the name
}
Thank You
1 Like
Kiwasi
June 29, 2017, 2:32am
2
What is the error message???
If you are just splitting by the underscore, n_s.Split(‘_’); will do that. That creates two strings. Just note the single quotes.
lol, @Kiwasi
string[] splitArray = n_s.Split(char.Parse("_"));
name = splitArray[0];
Edit: The error was “blah, blah closest overload match has invalid arguments”
3 Likes
Kiwasi
June 29, 2017, 6:45am
5
methos5k:
lol, @Kiwasi
string[] splitArray = n_s.Split(char.Parse("_"));
name = splitArray[0];
Edit: The error was “blah, blah closest overload match has invalid arguments”
It’s totally obvious once I see the error message. Error messages are our friends. And we all need more friends.
2 Likes
Indeed. Just cracked me up because of how people say they have an error but don’t write what it is
4 Likes
Can I split a XML by name ?
Example:
<?xml version="1.0" encoding="ISO-8859-1"?>
<enemys>
<node>
<name>Test 1</name>
</node>
<node>
<name>Teste 2</name>
</node>
</enemys>
Thank You
It’d be better to use an xml parser. (assuming you have to use xml)
Represents an XML document. You can use this class to load, validate, edit, add, and position XML in a document.
2 Likes