I am reading some code and I am struggling with the short syntax of trimming a short string readStudentData = line.Split(':')[1].Trim().Split(' '). (readStudentData is a string array). Can I get a little bit of explaination(the "[1]" part is the one that loses me)
It splits the string on the :. This returns an array. The [1] is an array indexing operation which returns the second item in that array. It then trims that item, and splits that on a space.
Let's consider a basic example. Say you have the string line = "title:hi bob "
line.Split(':') --> ["title", "hi bob "]
[1] --> "hi bob "
.Trim() --> "hi bob"
.Split(' ') --> ["hi", "bob"]
which gets assigned to the readStudentData variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With