string.format
-
I read many articles on String.Format, in my case I have a string variable that I want to specify its format 10a (a is alpha-numeric), I would like you to help me write this instruction , thank you in advance
I believe this should do it.
myString = myString.PadLeft(10);
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
I read many articles on String.Format, in my case I have a string variable that I want to specify its format 10a (a is alpha-numeric), I would like you to help me write this instruction , thank you in advance
If you want "10a" (as opposed to " a"), you would use
myString = string.Format("10{0}", a);
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
So in my case I have a table which contains 6 colomns which corresponds to a code and its value, and this table contains the characteristics of this value with format.donc to read a file from the code and its value must be correctly formatted according to the table, so I need to specify the format in 10 alpha numeric, so how do this??
I would recommend a validation process. If you try to format the return you will get spurious results. Try using Regular Expressions to validate the value.
^[a-zA-Z0-9]{10}\z
should do the job.If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
-
I read many articles on String.Format, in my case I have a string variable that I want to specify its format 10a (a is alpha-numeric), I would like you to help me write this instruction , thank you in advance
It's unclear what you are asking; please provide "before" and "after" examples.
-
I read many articles on String.Format, in my case I have a string variable that I want to specify its format 10a (a is alpha-numeric), I would like you to help me write this instruction , thank you in advance
myString = myString.PadLeft(10, '0');
would keep it all-alphanumeric. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
-
myString = myString.PadLeft(10, '0');
would keep it all-alphanumeric. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
string.Format("{0,10}", "a")
-
string.Format("{0,10}", "a")
that fills with spaces, one could argue the result isn't all alphanumeric. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
-
that fills with spaces, one could argue the result isn't all alphanumeric. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
-
string.Format("{0,10}", "a")
-
Dude - only you know the requirements.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001