UiPath string character count

In a string I have hyphen
Provide please the syntax to count the no of hypen in a string

Thanks in advance

grafik

1 Like

Hi @Ritaman_Baral

"Lak-sh-man-redd-dy".Count(Function(c) c = "-")

@Ritaman_Baral

Assign activity:

Variable: hyphenCount (Integer)

Value:
yourString.Count(Function(c) c = “-”)

image

1 Like

Hey @Ritaman_Baral
you can use:
numberOfHyphens = yourString.Count(Function(c) c = "-"c)
or
numberOfHyphens = yourString.Length - yourString.Replace("-", "").Length
or
numberOfHyphens = System.Text.RegularExpressions.Regex.Matches(yourString, "-").Count

1 Like

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