943,694 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 1213
  • C# RSS
Aug 13th, 2009
0

right, mid and left functions in c#

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
666kennedy is offline Offline
63 posts
since Mar 2008
Aug 13th, 2009
0

Re: right, mid and left functions in c#

To cut from the right, you can take a substring of a smaller length:
C# Syntax (Toggle Plain Text)
  1. string q = s.Substring(0, s.Length - 2) + somethingElse; // replace "mv" with something else
Reputation Points: 1446
Solved Threads: 135
Practically a Master Poster
Tom Gunn is offline Offline
681 posts
since Jun 2009
Aug 13th, 2009
0

Re: right, mid and left functions in c#

Use something like this:

c# Syntax (Toggle Plain Text)
  1. string testStr = "123XYZ";
  2. string leftStr = testStr.Substring(0, 2); // gives "12"
  3. string midStr = testStr.Substring(2, 3); // gives "3XY"
  4. 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.
Reputation Points: 2023
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,736 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: graphics issue
Next Thread in C# Forum Timeline: Problem with Alt-Tab while clipping mouse on Windows Vista





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC