Remove line in the middle and end of text file

I have some text files and I wish to remove all the lines below “Abbreviation” and also the line starting from “Paid-Up Capital Number of Shares Currency Share Type” to the line “Page 1 of 4ACCOUNTING AND CORPORATE REGULATORY AUTHORITY
(ACRA)”.

Example of my text file:
Name: Panda1
Role: Director
Adress: hello panda, street 51
postal code: 123456
Activities (I) : WHOLESALE TRADE OF A VARIETY OF GOODS WITHOUT A DOMINANT PRODUCT
(40000)
Description :

Activities (II) : WHOLESALE ON A FEE OR CONTRACT BASIS (EG COMMISSION AGENTS) (00100)
Description :

Capital

Issued Share Capital Number of Shares * Currency Share Type

(AMOUNT)

200000 200000 SINGAPORE, DOLLARS ORDINARY

  • Number of Shares includes number of Treasury Shares

Paid-Up Capital Number of Shares Currency Share Type

(AMOUNT)

200000 SINGAPORE, DOLLARS ORDINARY

COMPANY HAS THE FOLLOWING ORDINARY SHARES HELD AS TREASURY SHARES

Number Of Shares Currency

Authentication No. : L21057849820O

Page 1 of 4ACCOUNTING AND CORPORATE REGULATORY AUTHORITY
(ACRA)

WHILST EVERY ENDEAVOR IS MADE TO ENSURE THAT INFORMATION PROVIDED IS UPDATED AND CORRECT. THE AUTHORITY
DISCLAIMS ANY LIABILITY FOR ANY DAMAGE OR LOSS THAT MAY BE CAUSED AS A RESULT OF ANY ERROR OR OMISSION.

Business Profile (Company) of HELLO INTERNATIONAL PTE LTD (1999901281) Date: 30/01/1999
Abbreviation

UL - Local Entity not registered with ACRA

UF - Foreign Entity not registered with ACRA

AR - Annual Return

AGM - Annual General Meeting

FS - Financial Statements

FYE - Financial Year End

OSCARS - One Stop Change of Address Reporting Service by Immigration & Checkpoint Authority.

Authentication No. : L21057849820O

Page 3 of 4ACCOUNTING AND CORPORATE REGULATORY AUTHORITY
(ACRA)

WHILST EVERY ENDEAVOR IS MADE TO ENSURE THAT INFORMATION PROVIDED IS UPDATED AND CORRECT. THE AUTHORITY
DISCLAIMS ANY LIABILITY FOR ANY DAMAGE OR LOSS THAT MAY BE CAUSED AS A RESULT OF ANY ERROR OR OMISSION.

Business Profile (Company) of HELLO INTERNATIONAL PTE LTD (1999901281) Date: 30/01/1999

Note :

  • The information contained in this product is collated from lodgements filed with ACRA, and/or information collected by other government sources.
  • The list of officers for this entity is available for online authentication within 30 days from the date of purchase of this Business Profile. Please scan
    the QR code available on the last page of this profile to access the authentication page. For more information, please visit www.acra.gov.sg.

FOR REGISTRAR OF COMPANIES AND BUSINESS NAMES
SINGAPORE

RECEIPT NO. : ACRA2101290342224 (Free Business Profile by ACRA)

DATE : 30/01/1999

This is computer generated. Hence no signature required.

Authentication No. : L2105678899

Page 4 of 4

Hi @Leo88

Please find the sample xaml.

test.xaml (11.0 KB)

Code Used:

strText.Remove(strText.IndexOf("Paid-Up Capital Number of Shares Currency Share Type"),(strText.IndexOf("Page 1 of 4ACCOUNTING AND CORPORATE REGULATORY AUTHORITY"+Environment.NewLine+"(ACRA)")-strText.IndexOf("Paid-Up Capital Number of Shares Currency Share Type")+64))
strText.Substring(0,strText.IndexOf("Abbreviation")+12)

Input file used

jsonnn.txt (2.5 KB)

Ouput file

test5.txt (797 Bytes)

Thanks

Hi @prasath_S

I have this error when I tried the code. Kindly note that the example provided was a shortened version, there’s a lot of lines between the unwanted lines. Also, I can’t seem to open the xaml file.

Hi

Hope the below expression would help you resolve this

  1. Let’s take you have the above String in a variable named strinput

  2. Then use a assign activity like this

strinput = Split(strinput.ToString, “Abbreviation”)(0).ToString.Trim

  1. This will first remove all the lines after Abbreviation

  2. Now again use a assign activity like this

strinput_1 = Split(strinput.ToString,”Paid-Up Capital Number of Shares Currency Share Type”)(0).ToString.Trim

This will have the string part above this line
“Paid-Up Capital Number of Shares Currency Share Type”

And strinput_1 is a string variable

  1. Again use a assign activity like this

Strinput_2 = Split(strinput.ToString.Trim, “Page 1 of 4ACCOUNTING AND CORPORATE REGULATORY AUTHORITY
(ACRA)”)(1).ToString.Trim

This will have the string below this line
“ Page 1 of 4ACCOUNTING AND CORPORATE REGULATORY AUTHORITY
(ACRA)”

And strinput_2 is a string variable

  1. Now use a final assign activity to get the output we need

Str_final = strinput_1.ToString + Strinput_2.ToString

If you want a newline between them

Then it’s like this
Str_final = strinput_1.ToString + Environment.NewLine + Strinput_2.ToString

That’s it

Hope this would help you resolve this

Cheers @Leo88

@Palaniyappan thank for the reply. However I have this prompt "System.IndexOutOfRangeException: Index was outside the bounds of the array. " when I tried to do the assign below:
Strinput_2 = Split(strinput.ToString.Trim, “Page 1 of 4ACCOUNTING AND CORPORATE REGULATORY AUTHORITY
(ACRA)”)(1).ToString.Trim

1 Like

@Palaniyappan any idea how I can counter the problem? :cry:

Let me give a xaml on this

@Leo88

@Palaniyappan really appreciate that!

1 Like

Hi,

Can you try the following sample?

Sample20211110-a.zip (3.5 KB)

strData = System.Text.RegularExpressions.Regex.Replace(strData,"Abbreviation[\s\S]*$","")
strData = System.Text.RegularExpressions.Regex.Replace(strdata,"Paid-Up Capital Number of Shares Currency Share Type[\s\S]*?Page 1 of 4ACCOUNTING AND CORPORATE REGULATORY AUTHORITY\r?\n\(ACRA\)","")

Regards,

here you go with a xaml
split.zip (3.5 KB)

and this works as expected

Cheers @Leo88

@Palaniyappan the xaml file works! However, when I change the data to my own file, there’s the same error mentioned above. Im not sure whether it’s because im reading the text from a PDF file

@Yoichi your code run with no problem, but when I tried to write the final text on a text file, the text file is empty…and by the way Im reading from a PDF file

Hi,

Can you share you string data as a file using WriteTextFile activity?
There might be extra spaces and/or diffrent type whitespace etc.

Regards,

fine once after reading the data from PDF save that string in a string variable and pass that to a writeline activity
and see how the values looks like

we can follow the same steps as shared with SPLIT METHODS

Cheers @Leo88