How to manipulate a part of string: Split, Trim, Substring, Replace, Remove, Left, Right

Okay Patrick, I get it now. You only need to extract the ID numbers. :sweat_smile:

The solution is as follows:

splitedString = System.Text.RegularExpressions.Regex.Replace(inputString.Trim, "[^\p{N}]" , " ")

Change separator in “Split String” activity from "/" to " "

Then assign array to remove empty items:

splitedString = splitedString.Where(Function(x) Not String.IsNullOrWhiteSpace(x)).ToArray

Output data:

Hi Adrian,
Is working perfectly now and this is really cool and fun getting the robot to work…I learn something new each time I posted my problem and thank you so much for your time and guidance.

2 Likes

Great work, helps a lot. Thank you.

Hi Adrian,
Apologies to trouble you again, as I am trying to optimising the bots on some reducancy process and as of how could I remove those duplicate numbers in the array? I have try Union (from this link How to remove a duplicates values from the array and listbut couldn’t get the result.

Thanks you in advance for your help and guidance once again.

Hi @patrick-cm.kok
Have you checked this code from below?

Example data:

arr_numbers = {123456,123456,234567,345678,234567,456789,123456}
arr_strings = {"123456","123456","234567","345678","234567","456789","123456"}

Code:

arr_numbers = arr_numbers.Union(arr_numbers).ToArray
arr_strings = arr_strings.Union(arr_strings).ToArray

Result:

image

Hi Adrian,
Thanks you for your reply, I did try but couldn’t get the result as desired. Below are the screenshot for your reference.

Use :.Trim to replace white spaces from values. This seems to be the cause.

Thanks Adrian for your help, is there any proposal solution? I try to remove the duplicate first before the split but it don’t work as well.

Send the workflow and a file with sample data (they can be pseudo data)
I will take a look at what you have prepared and refer to it.

How to remove duplicate.zip (16.0 KB)
Hi Adrian,
Attach is the file and thanks you so much for your help in advance.

Check my work:
Remove_dupliate_values_in_array_of_string.zip (17,3 KB)

1 Like

Hi Adrian,
Your solution is very cools and I didn’t know it can be done this way. Something new to learn and thanks you so much for your solution and it work great!

Once again thank you so much.

2 Likes

Very informative. Thanks a lot.

Thanks you for this. This was really helpful!

Hi good morning.

I am creating a bot that captures a text of type Int from the screen and this captured text always changes length, going up to 5 characters or more. I need regardless of the fetched text to save the text from the first digit to the penultimate.

Can you help me please, thank you.

Hi @Melanny_Herrera_Cruz ,

You can use a regular expression:

output = System.Text.RegularExpressions.Regex.Match(inputString,"\b\d+(?=\d)").Value

output = String
inputString = String

Output as shown on screen:
image

Example link to visualize:

Pattern explanation:
start with the word boundary ( \b ),
get numbers that are more than 1 ( \d+ ),
end on a one-digit pattern without taking a character ( (?=\d) ).

1 Like

How to split the string if my string is of the format

Mat
cat
rat
fat

and I want one word at a time?

Can anyone help?

Hi,
solution to your problem:

arr_text As Array of Strings

arr_text = Split(your_text, Environment.NewLine)

Usage details in the first post:

2 Likes

Hi Adrian,

The above mentioned isnt giving me the result.
Can you show with a example

I am trying this

Split(Collection, Environment.NewLine)

where “Collection” is a string type variable

This worked for me - text.Split(Environment.NewLine.ToArray,StringSplitOptions.RemoveEmptyEntries)

Thanbk you