Loop through a string to list the capital letters

Hi,

I’m using C# and need some help in trying to identify the capital letters in a string. I understand that I have to use a ‘For Each’ activity (I think! :smiley:) because I have to go through the string character by character to check if it’s upper case, but I’m not sure how to do this.

Thanks

1 Like

Hi @paulparkes ,

Could you let us know with an example of what you want to perform or check ? Do you want to check if all the letters in a String are upper case ?

Hope the below steps would help you resolve this

  1. For dt get the array of characters from a text like this using assign activity

arrayvariable = value.ToCharArray()

Where arrayvariable is a variable of type array of string

  1. Now use a FOR EACH activity and pass the above array as input and change the type argument as string

  2. Inside the loop use a If activity like this

item.ToString.Equals(item.ToString.ToUpper)

If true it goes to then block and it’s in upper case
If false goes to else block and it’s in lower case

Hope this helps

Cheers @paulparkes

As mentioned by @supermanPunch it depends to your use case

Just to mentions some other options:
"Hello World".Intersect(Enumerable.Range(65,26).Select(x => (char)x)).ToArray()

  • Using Regex.isMatch / Matches
  • Using Linq Any / All / Where

Hi,

Sure, I’m using System.Environment.Username to get the username (FirstnameSurname) of the logged on user. The first letter of the first name and surname are capitalised. I’m trying to find a way to get the capitalised initials from the username.

Hope that helps

A simple pattern
grafik

Sorry, I’m still very new to this, is there an activity for Regular Expression??

you can use the Matches activity
https://docs.uipath.com/activities/other/latest/workflow/matches

I’m not seeing it when I search for it

Did this help you out
Let us know for any clarification @paulparkes

grafik

But we can also shorten to

Assign Activity
strInitials =
string.Join("", System.Text.RegularExpressions.Regex.Matches(strText, strPattern))

Kindly note: Short Statement has to be used on a Windows Compatibility Project
grafik

image

is ‘Matches’ one of these? These are the only ones that appear when I search

Find matching Patterns is the new name in your version

We hope you had noticed the oneliner:

I did thank you…

I wasn’t sure what this bit was though, so was trying to work it out

Trying it now, thank you

1 Like

strText = Your Input Text
strPattern = the Regex Pattern from Above: "[A-Z]"

[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

Perfect, thank you!

I’ll spend some time becoming familiar with ‘Matching Patterns’, I have a feeling it’ll be useful, but in the meantime, the Assign activity works perfectly!

Thank you so much!! :smiley:

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