Get substring from text file


#1

HI All
I encountered one problem when extracted string from text file.
eg: string = “Oct 22 2017 18:24:31: src inside:192.168.48.223/33991 dst outside:10.176.40.5/53 by access-group”

I want to extract substring ‘192.168.48.223/33991’ and ‘10.176.40.5/53’ from string.

how to do ?

Thanks a lot.


#2

Hi there @guanyan,
You can certainly achieve this via String manipulation.

I’ve attached a rough example for achieve this.

SubStringExample.xaml (8.8 KB)

With that said, it may be more interesting to achieve this via Regex:
RegexExample.xaml (6.6 KB)


#3

@guanyan,
Use This Regex Code in your Flow

(\d{1,3}).(\d{1,3}).(\d{1,3}).(\d{1,3})\W(\d{1,4})

and store in Array(Of String)
Array(0) is Date and Time
Array(1) is Inside Value
Array(2) is Outside Value

I hope this run Perfectly, Once you would change the order of the data…


#4

Hi, @guanyan

Instead of this statement You also Use the below Expression
(\d{1,3}).(\d{1,3}).(\d{1,3}).(\d{1,3})\/(\d{1,4})
It return Only inside and Outside value that can be stored in an Array
Note \/ This Not a Alphabet its a Symbol \ and /

Regards,


#5

OK ,thanks.


#6

HI

 Thanks a lot :grinning::grinning:

#7

Hi All,

Iam relatively New to UIPath.I have a scenario here.from one of the web pages Iam retrieving a invoice number .For example MS789695.
Now I want only 789695 out of it.But the length of the number is not fixed always,But one thing is always I have to remove first 2 characters out of the extracted one.

Thanks for your support.


#8

@shiva252,

Check this workflow, yo may get some idea.

ExtractStringForNumbers.xaml (5.6 KB)


#9

Thanks Sarathi,Actually I used substring as the value iam extracting is dynamic.Iam using substring(2,6).But iam not getting the proper results.correct me


#10

Try like this,

strInput.ToString.Substring(1, Len(strInput.ToString)-1)

I have used generic data type, so I have converted my strInput to string before us substring.


#11

Thanks Sarathi,

Iam using get text activity.In one browser iam getiing the correct value like cm12345 but when iam using the same function in another browser iam getting the result like \n\n\n\ncm12345\n\n.

why like this and how to write substring function.


#12

Hi,

Use the following statement and regex to remove \n - the new line character from your string, then go for substring as discussed earlier.

Regex.Replace(strInput, “\t|\n|\r”, “”)


#13

Hi ,

I need ur help in getting this resolved.Iam extracting a text from web page.Iam getting text like this .
\n\n\nName:JDavey Age:30 City:Newyork.

But I want the Output only JDavey , Here Name length may vary dynamically,But always present between Name: and Age:

Please !!


#14

Hi there @shiva252,
The below should work:

Assign - strSomeString =  \n\n\nName:JDavey Age:30 City:Newyork.
Assign - strSomeString = strSomeString.Substring((strSomeString.IndexOf("Name:") + 5), strSomeString.IndexOf("Age:") - (strSomeString.IndexOf("Name:") + 5))
Log - strSomeString

Result returned:
JDavey

Should function in any situation, as long as the structure remains the same.
As in, “Name:” and “Age:” are always in the same position.

Thanks in advance,
Josh Davey


#15

Thanks,

But if the length of the name changes from JDAVEY to JOSHDavey.


#16

Thanks a lot Josh. I got it.