string manipulation

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

Join Date: Mar 2007
Posts: 159
Reputation: mrjoli021 is an unknown quantity at this point 
Solved Threads: 0
mrjoli021 mrjoli021 is offline Offline
Junior Poster

string manipulation

 
0
  #1
Jul 28th, 2008
Is there a function that will remove the last 4 char of a string? trimend works but i have to specify which chars. what if i dont know what the chars will be. I still need to remove the last 4 chars. any ideas?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 6
Reputation: rsoliz is an unknown quantity at this point 
Solved Threads: 0
rsoliz rsoliz is offline Offline
Newbie Poster

Re: string manipulation

 
0
  #2
Jul 28th, 2008
Hello...consider the following:

  1. string testString = "Sometime";
  2. int startPos = testString.Length - 4;
  3. //call the string.Remove(int startPosition) method that deletes characters
  4. //starting from that specified position.
  5. //new string should show "Some"
  6. testString = testString.Remove(startPos);

Hope this helps...
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 59
Reputation: FaridMasood is an unknown quantity at this point 
Solved Threads: 0
FaridMasood's Avatar
FaridMasood FaridMasood is offline Offline
Junior Poster in Training

Re: string manipulation

 
0
  #3
Sep 3rd, 2008
  1. string test="GoodLuck";
  2. test=test.Substring(0,test.Length-4);

This will remove the last four characters from the string
Thanks and Best of Lusk,

Farid ud din Masood
MS.c (CS)
University of Agriculture, Faisalabad
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



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC