Remove some line from Text File

Hello, i needed help on this:

Input in text file:
Amount: $10
Name: May Ng (value of name changes)
Valid till: 31 Dec 2023 (value of date changes)
Country: Singapore

Output that i wan to achieve:
Amount: $10
Country: Singapore

Can help me on this?

We do have several Options:

Regex:

Assgin Activity
arrMatchedLines | DataType: StringArray =

System.Text.RegularExpressions.Regex.Matches(strIn, "^(Amount|Country).*").Cast(of Match).Select(Function (m) m.Value).toArray

Assign Activity:
strFiltered | DataType: String = String.Join(Environment.NewLine, arrMatchedLines)

1 Like

hi @f5f191b0815b26e83996fd67f

Regards,
Gayathri M K

Hi @f5f191b0815b26e83996fd67f

strinput= "Amount: $10
           Name: May Ng (value of name changes)
           Valid till: 31 Dec 2023 (value of date changes)
           Country: Singapore"
stroutput= System.Text.RegularExpressions.Regex.Matches(strinput,"(Amount:\s+|Country:\s+).+")

DataType of stroutput: IEnumerable(System.Text.RegularExpressions.Match)
=> Run a For each loop for the stroutput to get the values.

Hope it helps!!

Hi,

How about the following?

keywords = {"Amount","Country"}

Then

String.Join(vbcrlf,yourString.Split(vbcrlf.ToCharArray,StringSplitoptions.RemoveEmptyEntries).Where(Function(s)keywords.Any(Function(k) s.StartsWith(k))))

Regards,

1 Like

Thanks Yoichi, this works :slight_smile:

1 Like

i tried to use the method to get keyword (Honours) but it not successfully…
Input:

Text File 1
image

Text File 2
image

to achieve output:
Text File 1: 1st Class Honours
Text File 2: 2nd Class Honours

Hi,

The above expression extract line which starts with either of keywords.
If you want to extract line which contains either of keywords, can you try to replace StartsWith with Contains in the above expression?

Regards,

1 Like

thanks Yoichi :wink:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.