String manipulation-2

substring
#1

Hey all.

Trying to remove all the Alphabet letters in a string, but only from the start of the string. The Alphabets in the middle or end should stay. eg: ABC123X45DE would become 123X45DE. The number of letters at the start varies each time (same with total string length).

I think the best approach is to look at substring (0,1) inside a “while loop”, and IF it’s a letter, then: VARIABLE.ToString.Substring(1,(VARIABLE.ToString.Length-1))

MY QUESTION: What would be the best condition to use in the “While loop” please?
*Once first character is a number, then it would exit the While Loop and continue is my guess…but hey???

Thanks

#2

hello @MikeBlades i cant understand what you say. please clear more

1 Like
#3

@sandeep13 hey hey.

Trying to find the condition that will determine if first character in string is a Letter, but not a number. If it’s a letter, then i can then use a string length-1 to remove it (withing the While Loop), then re-check the condition on the next “first” letter…I have the the “remove first letter” sequence already (it’s in the While Loop and works), just need the Condition for the loop.

Example: ASD60001AB
The Condition would check the first letter (Using substring (0,1)) and because “Is first character a letter” Condition = TRUE, it goes into loop and removes first letter (with my already generated sequence), then does another loop to check the condition, then, if another letter, then remove again etc…until the first character is a number (eg: 6). This 6 would fail the condition and the While loop would exit…So whats the condition i need to create the While loop to do this?

Thanks

#4

Hi @MikeBlades,

Refer the below workflow for reference.

I have used a for loop for this, so i will be checking the characters in the string, if the character is a integer i will break the loop and check how many times the loop is rotated and the counter use in substring method.

ExtractString.xaml (6.3 KB)

Otherwise you can use Regular expressions to achieve this

regex.Match(str,"\d(.+)").ToString

ExtractStringUsingRegex.xaml (4.7 KB)

1 Like
#5
Regex.Replace(str,"^\D*","")

As regex is very powerful for string manipulation, you might want to take a look at https://regex101.com/ which is a great resource