Click here to Skip to main content
15,891,473 members
Home / Discussions / C#
   

C#

 
AnswerRe: string formate Pin
Ennis Ray Lynch, Jr.8-Jun-11 8:29
Ennis Ray Lynch, Jr.8-Jun-11 8:29 
AnswerRe: string formate Pin
mabrahao8-Jun-11 9:07
mabrahao8-Jun-11 9:07 
AnswerRe: string formate Pin
AspDotNetDev8-Jun-11 9:16
protectorAspDotNetDev8-Jun-11 9:16 
AnswerRe: string formate Pin
AspDotNetDev8-Jun-11 9:15
protectorAspDotNetDev8-Jun-11 9:15 
GeneralRe: string formate Pin
jashimu8-Jun-11 11:04
jashimu8-Jun-11 11:04 
AnswerRe: string formate Pin
Pete O'Hanlon8-Jun-11 10:55
mvePete O'Hanlon8-Jun-11 10:55 
GeneralRe: string formate Pin
AspDotNetDev8-Jun-11 11:38
protectorAspDotNetDev8-Jun-11 11:38 
AnswerRe: string formate PinPopular
Luc Pattyn8-Jun-11 12:32
sitebuilderLuc Pattyn8-Jun-11 12:32 
You should NOT do this with string manipulations; it would go completely wrong if the user types strange things, such as the intended number prefixed with a lot of zeroes.

The proper way to do this consists of two steps:

1.
parse the user input, i.e. turn his characters into an actual number. The simplest way would be:
int val;
bool OK=int.TryParse(myTextBox.Text, out val);


Whatever the user does wrong (e.g. typing letters, or providing no input at all) will result in OK being false; if the input is acceptable, OK will be true and val will contain its value.

2.
format the number in the way you want it. A simple way to get two spaces in a number assumed to require 8 digits is:
string s=string.Format("{0:## ### ###.##}", val);

Assuming val=12345678 the result will be 12 345 678

Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Please use <PRE> tags for code snippets, they improve readability.
CP Vanity has been updated to V2.3

GeneralRe: string formate Pin
AmbiguousName8-Jun-11 21:46
AmbiguousName8-Jun-11 21:46 
GeneralRe: string formate Pin
Lutosław11-Jun-11 12:13
Lutosław11-Jun-11 12:13 
AnswerRe: string formate Pin
Luc Pattyn11-Jun-11 12:17
sitebuilderLuc Pattyn11-Jun-11 12:17 
GeneralRe: string formate Pin
Lutosław11-Jun-11 12:45
Lutosław11-Jun-11 12:45 
AnswerRe: string formate Pin
Luc Pattyn11-Jun-11 12:51
sitebuilderLuc Pattyn11-Jun-11 12:51 
Questioninstantiating a generic object [modified] Pin
mabrahao8-Jun-11 5:53
mabrahao8-Jun-11 5:53 
AnswerRe: instantiating a generic object Pin
Ennis Ray Lynch, Jr.8-Jun-11 6:11
Ennis Ray Lynch, Jr.8-Jun-11 6:11 
GeneralRe: instantiating a generic object Pin
mabrahao8-Jun-11 7:43
mabrahao8-Jun-11 7:43 
GeneralRe: instantiating a generic object Pin
dasblinkenlight8-Jun-11 8:15
dasblinkenlight8-Jun-11 8:15 
GeneralRe: instantiating a generic object Pin
mabrahao8-Jun-11 8:36
mabrahao8-Jun-11 8:36 
GeneralRe: instantiating a generic object Pin
dasblinkenlight8-Jun-11 8:42
dasblinkenlight8-Jun-11 8:42 
GeneralFull example PinPopular
Ennis Ray Lynch, Jr.8-Jun-11 8:28
Ennis Ray Lynch, Jr.8-Jun-11 8:28 
GeneralRe: Full example Pin
mabrahao8-Jun-11 8:42
mabrahao8-Jun-11 8:42 
Questionitextsharp font question for pdf Pin
cromster8-Jun-11 3:42
cromster8-Jun-11 3:42 
AnswerRe: itextsharp font question for pdf Pin
BobJanova8-Jun-11 4:01
BobJanova8-Jun-11 4:01 
GeneralRe: itextsharp font question for pdf Pin
cromster8-Jun-11 4:28
cromster8-Jun-11 4:28 
GeneralRe: itextsharp font question for pdf Pin
BobJanova8-Jun-11 4:31
BobJanova8-Jun-11 4:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.