How to extract part of a string variable?

I have a string variable in C# in the follow format:


The “parts” of the string are always the same, however the “variables” change and so I have no way of knowing in advance what they will be. What I need is to be able to extract “variable1” only and store this in another string variable. I have tried using string split and trim, but because I don’t know how many characters long any of the “variables” will be, I’m not sure how far after the end of “part2” I should ignore/remove the rest of the string.

Any suggestions how to do this?

String.Split() returns the array of the string so If you use String.Split(“/”) , it’ll split the entire string into seaprate strings before and after the character “/”.

For example you have string “Variable1/Variable2”. if you use “Variable1/Variable2”.Split(“/”), you’ll have two different string “Variable1” and “Variable2” but you have to store it in array of the string like

string[] x = "Variable1/Variable2".split('/');

So you’ll have x[0] = “Variable1” and x[1] = “Variable2”;.

Now in your case I don’t see any need to know how long any string should be as you want to seaprately store the variable1. So Split() is the best option for you.

Hope it helped.