Need to split the string into two sub strings based on special characters(there is no particular length)


#1

I have data like this
1938-13545 - Wofsy - RM
256560 / 13933
Expert Witness ck beck an
28400/4692
Here i need to extract Digits only but i want like this 1938,13545 separately and remove other characters(in place of - we may also get any special characters based on that character i want to separate the data)

Output:
1938
13545
256560
13933
Empty
28400
4692


#2

Looking at your pattern, btw what will be your input? you can apply a for each loop on your content and string contains / then split according to it or else split by - this will give you array you can then access array items by indexes like array(0), array(1) and so on


#3

input :1938-13545 - Wofsy - RM
output : 1938
13545
input : Expert Witness ck beck an
output :
input : 256560 / 13933
output : 256560
13933

Each time i’m taking 1 string. If string contains only text then output is empty or it contains 1938-13545 - Wofsy - RM then the output is 1938 and 13545 separately. Thanks @prankurjoshi


#4

See this -

Main.xaml (9.2 KB)

This is very basic example you would have to optimize by string operations or matches it according to requirement. Let me know if this works. And if you want only number not text


#5

@sindhura506 Please find attached workflow.

new1.xaml (5.9 KB)


#6

Hello,

is your text contained in a file or in memory (ie variable) ?


#7

input is from excel. 1 column contains these strings. Thank you @mustafa.altinbasak


#8

My exact requirement is i need to print the text before special character and after special character up to space.if the string doesn’t contains any number we need to print empty.

Ex: i/p - 45454 @ 9898fgf kdmkjkjh dfdkjkl
o/p - 45454 and 9898fgf


#9

Then I guess you can use what @adarshk has suggested if you want other data as well from the string you will have to perform more string operation like I mentioned


#10

Thanks @adarshk … It is working…can i store output in two different variables?


#11

Shouldn’t it be as easy as creating 2 variables, and assigning them “item.ToString” as value ? :yum:


#12

@sindhura506 we should convert ienumerable to list or array, and then output the element in those to variables based on index.


#13

Try using regex options to extract only numbers rather than trying substring as the length is not fixed."/d" in regex should be able to give you all the digits present in the complete string


#14

good evening.

i have tried to get the specific number from a string which is stored in a variable.
for an example
stringtext(variable) = my 1st professional id is 7654367 for the company

from the above example i need to extract only that 7 digit number.

i have tried System.Text.RegularExpressions.Regex.Replace(demotest,"\D","")

but it returns the result including the number 1 from the second word of the string.

can anyone help me out with this. please.


#15

Hi @sathwikreddy

You were almost there, here’s a correction to your regex. Instead of removing the other non-digits in a string, you can directly select the first match of 7 consecutive digits, like this:

System.Text.RegularExpressions.Regex.Match(demotest,"\d{7}").ToString

#16

thanks for the solution. it helped a lot.