How to remove the specific part from the string

Hello,
1-PEPPAYACCTG QUEUE GL Reconciliation: PBC-US 20029004 ACCRUED UNION ADMIN PENSION P12 2018
2-PEPPAYACCTG QUEUE GL Reconciliation: PBC-Canada 20015403 RRSP Group P13 2018
3-PEPPAYACCTG QUEUE GL Reconciliation: PNB 20015408 EMPLOYEE PRETAX SAVINGS P01 2019

I have to remove the P12 2018 , P13 2018 , P01 2019 part from the above string 1 , string 2 and string 3.
here the the string to be removed can come anywhere in the main string.

Use regex “P\d{2} \d{4}”.
string = System.Text.RegularExpressions.Regex.Replace(string, “P\d{2} \d{4}”, “”)

Finds the letter P followed by 2 digits a space and then 4 digits and replaces it with an empty string.

4 Likes

You can try something like this (pseudo code):
myString = “1-PEPPAYACCTG QUEUE GL Reconciliation: PBC-US 20029004 ACCRUED UNION ADMIN PENSION P12 2018”

if (myString.Contains(“P12 2018”)) then
myString = myString.Replace(“P12 2018”, vbNullString)
end if

Here my string which I have to remove can be of format - P01 2019 , P02 2018 Like Pnumnum 20numnum

You should use here for ur scenario
stringvar.Substring(0,stringvar.Length-8)

Thankyou so much , it worked

1 Like

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