Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - format text

Reply
 
Old 04-14-2009   #1 (permalink)
Georg


 
 

format text

hi
i'am trying to format a string 123012345612 as follwed 123-0123456-12 i
am try to show this text in the propred mask. with left({sting},1) & "-"
&..... but did not succeesd. What i am doing wrong ?

regards , Gerog



My System SpecsSystem Spec
Old 04-14-2009   #2 (permalink)
Jesse Houwing


 
 

Re: format text

Hello Georg,
Quote:

> hi
> i'am trying to format a string 123012345612 as follwed
> 123-0123456-12 i
> am try to show this text in the propred mask. with left({sting},1) &
> "-"
> &..... but did not succeesd. What i am doing wrong ?
> regards , Gerog
What was the result? Why does it not match what you wanted? What is the exact
line of code?

It is very hard to answer your question with as little you've provided.

I'm guessing here, but I guess this would work. It does however not explain
why your original doesn't work.

You could use regex for this problem. And you could parse the number as an
int an use string.Format.

string value = "12345678901";
string formatted = string.Empty;
formatted = Regex.Replace(value, "^([0-9]{3})([0-9]{6})([0-9]{2})$", "${1}-${2}-${3}");
formatted = string.Format("{0:000-000000-00}", long.Parse(value));

--
Jesse Houwing
jesse.houwing at sogeti.nl


My System SpecsSystem Spec
Old 04-14-2009   #3 (permalink)
Jesse Houwing


 
 

Re: format text

Hello Georg,
Quote:

> hi
> i'am trying to format a string 123012345612 as follwed
> 123-0123456-12 i
> am try to show this text in the propred mask. with left({sting},1) &
> "-"
> &..... but did not succeesd. What i am doing wrong ?
> regards , Gerog
And tehn ofcourse there is the SubString function...

But I find the other two easier to read. (This one will be substantially
faster).

string value = "12345678901";
string formatted = string.Empty;

formatted = value.Substring(0, 3) + "-"
+ value.Substring(3, 6) + "-"
+ value.Substring(9, 2);

--
Jesse Houwing
jesse.houwing at sogeti.nl


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How Change Format to Plain Text? Live Mail
Rich text format to word format .NET General
Rich text format or HTML format Vista performance & maintenance
Text box format change .NET General
Mail Receipient - Plain text format? Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46