i have a tag;

XXX32353.mv

i need to be able to change the mv to something else, and the number of characters to the left of the . is not always constant. therefore i need to cut from the right, as the .mv is always the same,

what is the c# equivalent of this?

ive looked into substrings but that seems to be from the left only?

To cut from the right, you can take a substring of a smaller length:

string q = s.Substring(0, s.Length - 2) + somethingElse; // replace "mv" with something else

Use something like this:

string testStr = "123XYZ";
            string leftStr = testStr.Substring(0, 2);  // gives "12"
            string midStr = testStr.Substring(2, 3);   // gives "3XY"
            string rightStr = testStr.Substring(testStr.Length - 4, 4);// gives "3XYZ"

Perhaps you could make some methods from this and put them in a class of your own, if you like.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.