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
theo500
(Teodor Burlacu)
2
“hello”.Split("l"c).Length - 1
theo500
(Teodor Burlacu)
4
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
6 Likes
i have tried with below code
“hello”.Split("a"c).Length.tostring
i got result 1. here there is no letter “a” in hello word. then why i am getting result 1.
1 Like
vvaidya
(Vinay Vaidya)
7
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
Cheers
2 Likes
Hi,vvaidya
How to count of substrings like “hello” in string:" hello,hello world"