paulparkes
(Paulparkes)
October 23, 2023, 8:23am
1
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! ) 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
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
Now use a FOR EACH activity and pass the above array as input and change the type argument as string
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
ppr
(Peter Preuss)
October 23, 2023, 8:48am
4
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
paulparkes
(Paulparkes)
October 23, 2023, 8:49am
5
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
paulparkes
(Paulparkes)
October 23, 2023, 9:07am
7
Sorry, I’m still very new to this, is there an activity for Regular Expression??
ppr
(Peter Preuss)
October 23, 2023, 9:10am
8
paulparkes
(Paulparkes)
October 23, 2023, 9:24am
9
I’m not seeing it when I search for it
Palaniyappan:
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
Now use a FOR EACH activity and pass the above array as input and change the type argument as string
Inside the loop use a If activity like this
item.ToString.Equals(item.ToString.ToUpper
Did this help you out
Let us know for any clarification @paulparkes
ppr
(Peter Preuss)
October 23, 2023, 9:33am
11
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
paulparkes
(Paulparkes)
October 23, 2023, 9:52am
12
is ‘Matches’ one of these? These are the only ones that appear when I search
ppr
(Peter Preuss)
October 23, 2023, 9:54am
13
Find matching Patterns is the new name in your version
We hope you had noticed the oneliner:
paulparkes
(Paulparkes)
October 23, 2023, 9:57am
14
I did thank you…
I wasn’t sure what this bit was though, so was trying to work it out
ppr
(Peter Preuss)
October 23, 2023, 9:59am
16
paulparkes
(Paulparkes)
October 23, 2023, 10:02am
17
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!!
system
(system)
Closed
October 26, 2023, 10:03am
18
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.