Cutting/Delete string after specific symbol

Hello,

I was trying some things, but they didn’t work.

Example of the string: 123456/ABC/2019/UE
Expected result string:123456/ABC/19/UE

After the second slash “/” I must delete the first two digit, so instead of 2019, it must be 19, but the rest of the string must be the same.

Thanks in advance.

Ah this will be easy - but not without a couple assumptions.

  1. You can use RegEx
  2. Split string
  3. Sub string

The assumptions are the string has a fixed number of characters after every sforward slash…

If it is not so then revert with samples so that we can find a more flexible solution…

Also let me ask you this, are you looking for a solution or approach?

@Raghavendraprasad
Hello,
I assume that RegEx would be the answer.
Character is always fixed.
Looking for solution/also trying alone to get the solution(and I will post it if I found).

Well if the string is fixed and will vary only with the content then substring will be the easy way out.

Can you try the below method and revert?

YourFinalString=(Substring(0,11))+(Substring(13,OriginalString.Length))

1 Like

@Raghavendraprasad
I think I’m doing something wrong.

@Veselin_Ganchev

StrVar= “123456/ABC/2019/UE”
OutString=StrVar.Substring(0,11)+StrVar.Substring(13,5)

1 Like

str.remove(str.indexOf("/", str.indexOf("/") + 1)+1,2).ToString

Thanks!

@kadiravan_kalidoss
Thank you but I don’t understand your proposal.
Would you like to explain?

Ah i wrote the C# syntax I guess… well…

the str.remove function will get the position of the delimiter (/) and then remove it which will help you not to code the index number into your assign statement itself…any which way works is fine i guess

Hi @Veselin_Ganchev,

Using this Method to find the index of 2nd occurrence of “/”.

IndexOf(String, Int32) Reports the zero-based index of the first occurrence of the specified string in this instance. The search starts at a specified character position.

str.indexOf("/", str.indexOf("/") + 1)+1 - this will return the index of second occurrence("/").
And it will start searching from index 7 (str.indexOf("/") + 1).

Then, using remove method to remove 2 characters from the starting index.

Remove(Int32, Int32) Returns a new string in which a specified number of characters in the current instance beginning at a specified position have been deleted.

Thanks!

1 Like

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