Showing posts with label integer. Show all posts
Showing posts with label integer. Show all posts

Saturday, March 31, 2012

string to integer

Hello

I need to do something like this, read data from text file and use it as integer. How can I do it?

Please help me...

Artur

myString = "1234"

myInt = CInt(myString)


Is the text that you are retrieving strictly a number, or is it a combination of text and numbers where you only want to get the numbers? If it's just numbers, you can use Integer.Parse() in VB.NET or int.Parse() in C#.

To read a text file, you use the System.IO namespace. The TextReader Class on MSDN has an example of using a TextReader to get the contents of a text file.

TextReader Class

If the variable m_Text contained the contents of the text file, then here is how you would use Integer.Parse:

VB.NET
Dim m_NumberAs Integer
m_Number =Integer.Parse(m_Text)

C#
int m_Number;
m_Number =int.Parse(m_Text);

HTH


If you are expecting it to be numbers either of the ways above will work however if you try to cast you might want to wrap it in a try to catch any problems in case someone does put in non number data

String to integer conversion

Hello!

Class int has a method for conversion numeric values to strings (ToString() method). Is there any similar method or function, which converts a string into Int32 type?

Cheers!static method System.Int32.Parse()
Thanks!
Hello!

I tried to use the method you gave me, but got an error message: "System.FormatException: Input string was not in a correct format."
Maybe there is any special way I should use it?

Here's how I do it:


void Fill_End_Day(int auto, int aasta, int kuu, int paev) {
autorent.broneering wsProxy = new autorent.broneering();
System.Data.DataSet ds;
ds = wsProxy.JargmineHyiv(auto, aasta, kuu, paev);
int i;
for (i=paev; i<System.Int32.Parse(ds.Tables[0].Rows[0]["paev"].ToString()); i++)
DropDownList7.Items.Add(i.ToString());
}

Is there something wrong with it?

Cheers.
c# doesn't have cInt()?
I'm afraid it doesn't. Maybe there is some similar function, but I can't even assume in which class I should seek for it.
Sorry, it works now! It should have worked from the beginning, but there has been a stupid mistake in another palce.
Thank you!

Saturday, March 24, 2012

Strip characters from string

Hi, I want the user to be able to enter any form of number in my price textbox and I will automatically strip anything that is not an integer.

I obviously can't mand a string.replace for every character, so is there a way to use a regexp to say anything that isnt 0-9?

Thanks, Davehello, u can add a validation control to the textbox with the following:

[0-9]+

this way, they can enter any number they want.
But I don't want to have to restrict it like that. Many people will enter different formats for a price. I want them to be able to use '$' or ',' or whatever and have it stripped on the backend.

I am looking at regex.replace, but I can't get it to work yet.
well,
maybe u can allow them to enter any number or character and the loop through an array of all alphabets and eleminate all not needed characters !!!
I can offer you a commercial solution. My productProfessional Validation And More includes IntegerTextBox, CurrencyTextBox, and DecimalTextBox fields. They handle the filtering of illegal keystrokes, reformatting as the user exits the field, and supply you with the actual numeric value (an integer or Double property) on the server side.