right, mid and left functions in c#

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 63
Reputation: 666kennedy is an unknown quantity at this point 
Solved Threads: 0
666kennedy 666kennedy is offline Offline
Junior Poster in Training

right, mid and left functions in c#

 
0
  #1
Aug 13th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 681
Reputation: Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of 
Solved Threads: 133
Tom Gunn's Avatar
Tom Gunn Tom Gunn is offline Offline
Practically a Master Poster

Re: right, mid and left functions in c#

 
0
  #2
Aug 13th, 2009
To cut from the right, you can take a substring of a smaller length:
  1. string q = s.Substring(0, s.Length - 2) + somethingElse; // replace "mv" with something else
-Tommy (For Great Justice!) Gunn
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,978
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 288
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: right, mid and left functions in c#

 
0
  #3
Aug 13th, 2009
Use something like this:

  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.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC