finding character in string

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

I want to find a particular character in a string, and then find the
length of the string after this point in the string, so that I can do a
rightpad on it if it is of a certain length (basically I want to pad a
monetary value if it is for example 12.5, so that it becomes 12.50).

I can think of a long winded way to do it by using a foreach loop to
find the '.', but is there a specific function in C# to find a character
in a string?


Cheers,

Mike
 
hi Mike,

use the method String.IndexOf(char) to find the position
of a character.

Cheers
Marcello
 
Thanks for your help everybody. I've found a much easier way to do what
I was trying to do, simply formatting the string as a currency :

String.Format("{0:c}", string);


Cheers,

Mike
 
Back
Top