Count characters in a string

I need to count the number of characters in a string.

I’ve tried this code:
“hello”.Length - “hello”.Replace(“l”,"").Length

I tried also:
len(“hello”) - len(“hello”.Replace(“l”,""))

But in both cases I’m getting an error like ’ Option Strict On disallows implicit conversions from ‘Integer’ to ‘string’’

What is the right command to count the length of a string?

1 Like

“hello”.Split("l"c).Length - 1

I have the same error:

it is missing the conversion to string type (as the formula returns an integer).

in a messagebox will look like:
(“hello”.Split("l"c).Length - 1).ToString


Fantastic, thanks!!

i have tried with below code


i got result 1. here there is no letter “a” in hello word. then why i am getting result 1.

1 Like

your result is the count of substrings after splitting “hello” word with “a”, not the occurences of “a” letter.

To get the count you should do “hello”.Split("a"c).Length-1

1 Like

An alternative Linq solution handling both lower and upper Cases

"UIPATH".Count(Function(c) LCase(c)="a").ToString




How to count of substrings like “hello” in string:" hello,hello world"