"SamIAm" <sa****@rubbach icken.com> wrote in message
news:Od******** ******@TK2MSFTN GP10.phx.gbl...
How do I extract the last 3 characters of a string i.e.
string s = "000001" I want "001"
Probably overkill for your current problem, but you can use an Regular
Expression [RE] to select the part of the string that you want, in this
case, it would be @".{3}$". You would be amazed at what can be accomplished
with RE's ! Below is some sample code, though I'd recommend you consult the
relevant documentation and a tutorial or two :) !
I hope this helps.
Anthony Borla
using System;
using System.Text.Reg ularExpressions ;
public class RegexExample
{
public static void Main()
{
String str = "000001";
Regex re = new Regex(@".{3}$", RegexOptions.No ne);
MatchCollection mlist = re.Matches(str) ;
if (mlist.Count > 0)
Console.WriteLi ne("str = {0}, match = {1}", str, mlist[0].Value);
else
Console.WriteLi ne("No match!");
String substr = mlist[0].Value.ToString ();
}
}