SkipWhile function for Strings

Jas91

Member
Joined
Jul 12, 2012
Messages
17
Location
Baghdad, Italy. OK?=
Programming Experience
5-10
how does it really work? can't fully figure out its real purpose because I couldn't find good examples/documentations on the internet

This is what I have to do:

I have a var string "str1" which contains a text
and a var string "str2" where I have to copy to, a substring of str1 from its the last char "c" till the end of the string
 
Enumerable.SkipWhile(TSource) Method (IEnumerable(TSource), Func(TSource, Boolean)) (System.Linq)
It is an extension method, in this case it extends String because that is a IEnumerable(Of Char). It's purpose is the same for all collections it extend, and that is:
Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.
I would say that is not relevant for what you're trying to do. You can find the last index of a char using String.LastIndexOf method, and then String.Substring method to return the remaining string from that index.
 
You could use SkipWhile for that purpose like this:
str2 = New String(str1.SkipWhile(Function(ch) ch <> "c"c).ToArray())
Most likely LastIndexOf and Substring would be faster though, although the difference may be slight.
 
Back
Top