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