What is the output of this code and why?How does it work ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the output of this code and why?How does it work ?

var str = "-Solo--Learn-".Split('-'); Wrireline(str.Length); 2 4 5 9

8th Dec 2019, 5:51 AM
Khachatur Melkonyan
Khachatur Melkonyan - avatar
2 Answers
+ 1
Please edit your question and specify the language (presumably C#) Khachatur Melkonyan Thank you for understanding. The code output would be 5. Explanation: "-Solo--Learn-" is a string literal, which will be splitted using hyphen as the delimiter. The `Split` method of the string class will do the work. The result is presumably a string array containing parts of the string which are not hyphen. {"", "Solo", "", "Learn", ""} This are the array contents (result from splitting the string). Hth, cmiiw
8th Dec 2019, 7:14 AM
Ipang
+ 1
Thank you
8th Dec 2019, 8:09 AM
Khachatur Melkonyan
Khachatur Melkonyan - avatar