Showing posts with label weird. Show all posts
Showing posts with label weird. Show all posts

Monday, March 26, 2012

string.ToString (IFormatProvider) doesnt take case of the provider ?

It's seem like a bug in the framework... but I'm not sure...
It's must seems weird, but I have a string variable and I want to apply a format and get the string formatted in that format. My original string is a numeric value and I want to obtain a string formatted based on the culture of the current thread.
string numericValue = "1234.56";
string returnValue = numericValue.ToString (System.Globalization.NumberFormatInfo.CurrentInfo);
But, it doesn't work. So, I check the code in the framework and there two methods ToString on the string Object. And both, return the this even the one with the provider parameter.

publicstringToString(IFormatProvider provider){returnthis;}
I you agree with me that there is a bug in the framework ?

hello.
i think that you're seeing it the wrong way.
what you want to do is get your number (ex.: double) and use the ToString method of that struct.
Double num = ...;
num.ToString( provider );
i think that using tostring with a provider on a string doesn't make any sense...

What I am trying to do is converting the format of a string from one culture to another. Say that you have a string 1 234,56 on the french-Canada culture and want to format the string to the english-US culture. I can parse the string to double and returning back to string. But I see that the string class have a method ToString who take a FormatProvider and do nothing with the parameter.


hello.

what i was trying to say is that if you're supposed to have a number, then use a variable of the desired type to keep it and parse it to the desired culture.


My simple solution is:
private void Form1_Load(object sender, EventArgs e)
{
double i = 1234.56;
textBox1.Text = i.ToString("0,000.00");

}

Saturday, March 24, 2012

Stripping text files

Hi all,

I'm trying to have my ASP.NET application read in a text file, and put the characters into a string.

I realized that there are some weird symbols (a square) between the texts - I think it's either a carriage return or a newline character, and want to take them out by the Trim method.

Does anybody know how I can remove those symbols? Thanks!You can use this overload

public string Trim(params char[]);
, if you know which characters you want to remove.
Most likley candidates are chr(10) (carriage return) followed by chr(13) line feed, especiallly if you are working with report files or anything unix based.

Regards

Jeff............