I have a complex string value and I want to remove the part between two words

(…)
DİPNOT
BİLANÇO DİPNOTLARI
1- eqafu
2- adehuDİPNOT sdvs
3- usrfd
4- dhsaj
5- dshgaj:
Döviz Cinsi Miktarı TL Kuru Toplam Tutar (TL)
TL -
EUR x y z
USD k l m
GBP 145,88 37,4417 5.462,00
Yurt dışından alacaklar (avanslar dahil ):
Döviz Cinsi Miktarı TL Kuru Toplam Tutar (TL)
EUR x y z
USD - l -
Yurt içinden alacaklar (avanslar dahil ):
Döviz Cinsi Miktarı TL Kuru Toplam Tutar (TL)
EUR x y z
USD - l -
10- lvjkvl
(…)

PASİF

I want to remove the parts between DİPNOT and PASİF without damaging the structure of the my string value, because the data before and after is important to me. How can i do that?

Hi @HaticeKubraYilmaz

can you share the expected output.

Hi @HaticeKubraYilmaz , I’m thinking on possibly using Regex Replace to find the string between your 2 keywords, and then replacing it with a String.Empty, should look something like this:

System.Text.RegularExpressions.Regex.Replace(strTest,“(?<=DİPNOT).*(?=PASİF)”,String.Empty,System.Text.RegularExpressions.RegexOptions.Singleline)

image

Edit: If you also want the 2 keywords to be deleted, you can modify a bit the regex expression:

System.Text.RegularExpressions.Regex.Replace(strTest,“DİPNOT.*?PASİF”,String.Empty,System.Text.RegularExpressions.RegexOptions.Singleline)

image

1 Like

@HaticeKubraYilmaz

You can use this…I hope the strings you mentioned are only coming once

use assign

requiredstring = str.Split({"DIPNOT","PASIF"},StringSplitOptions.None)(0) + str.Split({"DIPNOT","PASIF"},StringSplitOptions.None)(2)

cheers

Thank you, it worked for this part but the word “PASİF” was mentioned elsewhere and I removed out the parts I didn’t want. How can I clean up the space between DİPNOT and the first PASİF word?

Unfortunately not once :smiling_face_with_tear: There are also below but I want the first ones

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