format text

  • Thread starter Thread starter Georg
  • Start date Start date
G

Georg

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
 
Hello Georg,
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));
 
Hello Georg,
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);
 
Georg said:
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

Hi Georg,

In addition to Jesse's solutions you can also use String.Insert

string s = "123012345612";
s = s.Insert(10, "-").Insert(3, "-");

If you are trying to add the - using a mask, try ###-#######-##
 
hi ,
i've tried this on a textfield in a crystalreport., but did not succeed
Before , i used only ms access and i did it with an inputmask in the table
as followed 000"/ "0000000" / "00
how i can managed this in a crystal report ?
regards, Georg
 
Sorry, can't help you there. You might want to start a new thread with
crystal report somewhere in the subject.

--
Happy Coding!
Morten Wennevik [C# MVP]

Georg said:
hi ,
i've tried this on a textfield in a crystalreport., but did not succeed
Before , i used only ms access and i did it with an inputmask in the table
as followed 000"/ "0000000" / "00
how i can managed this in a crystal report ?
regards, Georg
 
hi,
thx anyway, georg


Morten Wennevik said:
Sorry, can't help you there. You might want to start a new thread with
crystal report somewhere in the subject.

--
Happy Coding!
Morten Wennevik [C# MVP]

Georg said:
hi ,
i've tried this on a textfield in a crystalreport., but did not succeed
Before , i used only ms access and i did it with an inputmask in the
table
as followed 000"/ "0000000" / "00
how i can managed this in a crystal report ?
regards, Georg

"Morten Wennevik [C# MVP]" <[email protected]> schreef in
bericht
:

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


Hi Georg,

In addition to Jesse's solutions you can also use String.Insert

string s = "123012345612";
s = s.Insert(10, "-").Insert(3, "-");

If you are trying to add the - using a mask, try ###-#######-##
 
Back
Top