Get the length of the sentence

I have a sentence where I need to get the number words in that sentence how could I achieve this.

1 Like

@soumi_soumiya

StrOut=InputStr.count.ToString

1 Like

@soumi_soumiya
Split the string using yourstring.Split({" "}, StringSplitOptions.None) this will give you Array of string then use ArrayVar.count this will give you number of words present in the sentence.

Regards

1 Like

@soumi_soumiya Split the sentence with respect to space and use count method on it, then you will get number of words in that sentence.

Ex: Str = “How are you”

int WordCount = Str.Split({" "},StringSplitOptions.RemoveEmptyEntries).Count

1 Like

hi @soumi_soumiya

split based on the space and get the count of the array.

count = InputString.Split("").Count

Regards
Ajay

1 Like

Hi @soumi_soumiya,
Int var= yourString.split(" "C).count

Thanks!

Thanks for your reply…

I have done but it gives me only the number of letter in the sentence not the number of words

@soumi_soumiya

Try this.
count = InputString.Split(" "c).Count.ToString

1 Like

“place your sentence here”.count.ToString

1 Like

split the string and then use count function on the array.

1 Like

I have created zip file based on your requirement.

forum.zip (19.9 KB)

Regards,
Mohanraj.S

2 Likes

Thanks for your reply…
I have an other concern is that i have a paragraph where i need to know how many lines are there how could i achieve it

StrOut=InputStr.Split({Environment.NewLine}, StringSplitOptions.None).Count.ToString

1 Like

for Paragraph you need to split the string based on the Environment.newline

Hi,
It is a different approach using the regex.

intCount= Regex.Matches(strString, “\S+”).Count

image

test.xaml (4.8 KB)

output
image

Regrads
Balamurugan.S

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.