Mike,
As a general rule, when dealing with anything in .NET/C#, everything
runs off a zero-based index (there are probably exceptions, but for the most
part, this is true).
The Substring method is the same. So, if you want to get the last four
characters, you can do this:
strCardNumberUnEnc =
strCardNumberUnEnc.Substring(strCardNumberUnEnc.Le ngth - 4, 4);
Which is basically what you had. You don't need the call to convert,
since the Length property returns an int.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
ni**************@exisconsulting.com
"Mike P" <mr*@telcoelectronics.co.uk> wrote in message
news:uQ**************@TK2MSFTNGP11.phx.gbl...
If I want to get the last 4 characters of a string is this the right way
to do it?
int intCardLength = Convert.ToInt32(strCardNumberUnEnc.Length);
strCardNumberUnEnc = strCardNumberUnEnc.Substring(intCardLength -
4, 4);
Or is there stuff (Length, Substring) that is zero-indexed that will
mean I need to take account of?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!