I have a long string of characters as input and I want to count the number of words in that string. How can I do it through regular expression?
coder389
0
Newbie Poster
Recommended Answers
Jump to PostThe simpliest way would be to spit the string by white spaces into string array, and count the words (by Length property):
string text = "you long string"; string[] splitted = text.Split(' '); int wordsCount = splitted.Length;
Or even better (shorter), by using Linq:
Jump to PostI would like you to continue using Linq, which is really some piece of work from MS.
To get 1st 50 words:
string text = "you long string"; var result_1st50 = text.Split(' ').Select(s=>s.Lenght).Take(50).ToList();
To get next 50 (and skip 1st 50):
var result_1st50 …
All 5 Replies
Mitja Bonca
557
Nearly a Posting Maven
coder389
commented:
Now, how will I display the first 50 words, then next 50 words and so on?
+0
coder389
0
Newbie Poster
Mitja Bonca
557
Nearly a Posting Maven
Momerath
1,327
Nearly a Senior Poster
Featured Poster
Mitja Bonca
557
Nearly a Posting Maven
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.