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

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

@Adrian_Star,
I cannot thank you enough your article has been very useful in making me understand string manipulation.

I have written a regex that seems to be working but I get this error:
Self referencing loop detected with type ‘System.Text.RegularExpressions.Match’. Path ‘Groups’.
Could you be having an idea on how to resolve it please.

Thank you.

Best Regards,
Kakooza Allan Klaus

Hi @Kakooza-Allan-Klaus ,
Please include your regex pattern here along with a description of what you want to extract. Also include sample text with data. Then I will be able to check the pattern and give you the answer.

1 Like

Hi @Adrian_Star,

As requested.

C:\\\w*\s*\w*\\\w*.xlsx

C:\folder Name\6639a06d28484664ac15dfedf95a0e37.xlsx

Best Regards,
Kakooza Allan Klaus

sample = "C:\folder Name\6639a06d28484664ac15dfedf95a0e37.xlsx"
pattern = "C:\\[\w\s]+\\\w+.xlsx"
regex_result = System.Text.RegularExpressions.Regex.Match(sample, pattern).Value

Do you have a logical expression like mine in the regex_result variable?

1 Like

Yes,
But the are patterns are different
I want to know what could have been wrong with mine.

Yours is very stable

The difference is slight.
In my formula, I just optimized regex pattern by fitting a result with a range of \w and \s characters.
What does it mean. I grouped the characters \w and \s in to [] bracket and assigned them: + - that is, to match each type of word characters and whitespace in any number starting from 1.

1 Like

Hi @Nasya.Idris I have seen it was questioned long back. Still posting the link for your question through my short video.
Hoping it would help, if anyone approaches here with same question or you can even refer for the better and single liner approach.

This was treasure

Very good post. This has helped me several times :slight_smile:
Thanks for sharing!

Hello there,

Is there any way to remove the bullet point without text through automation in word?

TestText.replace(“•”,“”)

I used the assign method for removing the bullet. The left variable (“ohne_Aufzählungspunkt”) represents the variable for the result of the execution. For the right variable (“Aufzählungspunkt”), the enumeration point should be removed using enumeration_point.Replace("• ", “”). Unfortunately this does not work. Is there a better way to do this?