String Operations without Regex Expressions

Hi I have an alphanumeric string and I need to get total number of 1’s present it. How can we acheive this other than regex using uipath?

Ex: Input - 113ABC101
Output- 4

Hi,

You can get it as the following.

count = strData.Length - strData.Replace("1","").Length

Regards,

1 Like

@ajaysimha6,

You can do that by the following expression.

strInput.Split("1"c).Length - 1

assign this to an integer variable

1 Like

I know We can do using VB Expression but any other way we can achieve?

Hi,

How about the following?

strData.Where(Function(c) c="1").count()

Regards,

1 Like

@ajaysimha6,

“113ABC101”.ToCharArray() convert your string into a Char.

Then in a for each you can check each character and if it is “1” then increase the counter.

This is the legacy and classic way of doing it.

You can use the ‘Count’ overload that takes a predicate like below
yourvariable.Count(Function(x) x = (“1”))

1 Like