Hello,
I have a problem, I'm hoping someone can help.
I have a string, lets say: "111111"; // Not always numeric
I have a format mask, lets say: "(00) 0000"; // Again, not always
numeric.
The mask and the value are passed into a method.
private string GiveMeTheFormattedString(string i_Value, string i_Mask)
{
}
I want the output of this method to be: "(11) 1111"
Remember, I can't assume that my input string or my mask will be
numeric and the mask will be different.
Help. :-)
I've tried this:
string retVal = String.Format("{0:" + iMask + "}", i_Value);
No luck, it always comes back as the original input.
I even tried the above hard coding the format mask in, i.e. ("{0:(00)
0000}",i_Value);
still no luck.
Thanks for the help, in advance.
John 6 2576
What is the function in VB that you use to do this? More than likely,
it exists in the Microsoft.VisualBasic namespace. You can add a reference
to Microsoft.VisualBasic.dll and use the method that you know will work
(rather than write your own).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
<jm*****@forte-industries.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Hello,
I have a problem, I'm hoping someone can help.
I have a string, lets say: "111111"; // Not always numeric
I have a format mask, lets say: "(00) 0000"; // Again, not always
numeric.
The mask and the value are passed into a method.
private string GiveMeTheFormattedString(string i_Value, string i_Mask)
{
}
I want the output of this method to be: "(11) 1111"
Remember, I can't assume that my input string or my mask will be
numeric and the mask will be different.
Help. :-)
I've tried this:
string retVal = String.Format("{0:" + iMask + "}", i_Value);
No luck, it always comes back as the original input.
I even tried the above hard coding the format mask in, i.e. ("{0:(00)
0000}",i_Value);
still no luck.
Thanks for the help, in advance.
John
In VB, I'd use the Format function.
As I bring code forward from the VB6 world, I'm supposed to work under
the Mantra:
VB = Bad;
VC# = Good.
:-)
So, if I can do it, I'd like to not use the VB namespace.
John
In VB, I'd use the Format function.
As I bring code forward from the VB6 world, I'm supposed to work under
the Mantra:
VB = Bad;
VC# = Good.
:-)
So, if I can do it, I'd like to not use the VB namespace.
John
Bad mantra, especially if you don't have a C++ background. VB 2005 is just
as expressive as VC#. Yes, there are some differences between the
languages, but they are functionally 99+% identical and both are fully
supported by MS.
Mike Ober.
<jm*****@forte-industries.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
>
In VB, I'd use the Format function.
As I bring code forward from the VB6 world, I'm supposed to work under
the Mantra:
VB = Bad;
VC# = Good.
:-)
So, if I can do it, I'd like to not use the VB namespace.
John
See inline.
Willy.
<jm*****@forte-industries.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
| Hello,
|
| I have a problem, I'm hoping someone can help.
|
| I have a string, lets say: "111111"; // Not always numeric
| I have a format mask, lets say: "(00) 0000"; // Again, not always
| numeric.
|
Not sure what you mean with one/both not always being numeric.
But here is how you can format a string.
Here suppose the Mask is ("(000) 0000") and the string something like
"1234567" or " 123.2356" or " +1.234567 " ...
private string GiveMeTheFormattedString(string i_Value, string i_Mask)
{
double dv;
if(Double.TryParse(i_Value, NumberStyles.Number,null, out dv))
return dv.ToString(i_Maks);
else return null;
}
If this doesn't suits your needs you will have to implement your own
IFormatProvider.
| The mask and the value are passed into a method.
|
| private string GiveMeTheFormattedString(string i_Value, string i_Mask)
| {
|
| }
|
| I want the output of this method to be: "(11) 1111"
|
| Remember, I can't assume that my input string or my mask will be
| numeric and the mask will be different.
|
| Help. :-)
|
| I've tried this:
|
| string retVal = String.Format("{0:" + iMask + "}", i_Value);
|
| No luck, it always comes back as the original input.
|
| I even tried the above hard coding the format mask in, i.e. ("{0:(00)
| 0000}",i_Value);
|
| still no luck.
|
| Thanks for the help, in advance.
|
| John
| jm*****@forte-industries.com wrote:
Hello,
I have a problem, I'm hoping someone can help.
I have a string, lets say: "111111"; // Not always numeric
I have a format mask, lets say: "(00) 0000"; // Again, not always
numeric.
The mask and the value are passed into a method.
private string GiveMeTheFormattedString(string i_Value, string i_Mask)
{
}
I want the output of this method to be: "(11) 1111"
Remember, I can't assume that my input string or my mask will be
numeric and the mask will be different.
OK, so what do you want the output to be in these cases:
input: abcdef
mask: (00) 0000
input: -3.14592536
mask: (0) 0-0 (0)
input: 1A2B3C
mask: 00abcdef
?
IF your input is an integer and you want to use a custom numeric format
string, cast to an integer and use ToString():
string formatted = 111111.ToString("(00) 0000");
// now formatted == "(11) 1111"
To be able to say how to produce results in other cases, we would need
to know what you want to see in those other cases.
--
Larry Lard la*******@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Oliver S. |
last post by:
I've developed a string-class that holds the string in an array which
is a member-variable of the class and that has maximum-size which is con-
figurable through a template-parameter. If any...
|
by: hagai26 |
last post by:
I am looking for the best and efficient way to replace the first word
in a str, like this:
"aa to become" -> "/aa/ to become"
I know I can use spilt and than join them
but I can also use regular...
|
by: Dennis Myrén |
last post by:
Hi.
Is there a way to utilize the great primitive data type
formatting routines available in .NET without working with
strings?
I want a byte directly rather than a string.
I think it is...
|
by: ilona |
last post by:
Hi all,
I store phone numbers in the database as 123447775665554(input mask is used
for input, and some numbers have extensions), and I also know from db if the
number is Canadian, US, or some...
|
by: Lauren Wilson |
last post by:
Hi folks,
We have a need to replace sub strings in certain message text. We use
the Office Assistant to display help and often use the imbedded
formatting commands. Those of you who have used...
|
by: angellian |
last post by:
Sorry to raise a stupid question but I tried many methods which did
work.
how can I conserve the initial zero when I try to convert STR(06) into
string in SQL statment?
It always gives me 6...
|
by: L. Scott M. |
last post by:
Have a quick simple question:
dim x as string
x = "1234567890"
-------------------------------------------------------
VB 6
dim y as string
|
by: Dustan |
last post by:
Is there any builtin function or module with a function similar to my
made-up, not-written deformat function as follows? I can't imagine it
would be too easy to write, but possible...
'I am...
|
by: schoedl |
last post by:
Hello,
we often compose strings via a ostringstream and then create a string
from it. What is the rationale of not being able to use string in
place of a ostringstream, so I could write
...
|
by: SammyBar |
last post by:
Hi all,
I'm trying to convert the xml obtained from a XmlReader object into a UTF-8
array. My general idea is to read the XmlReader and write into a
MemoryStream. Then convert the MemoryStream...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |