Kind of a newbie question, but I need to be able to convert a string to
an integer in C#, similar to VB's Val(). Anybody know how to do this?
I've tried C-style casting (obviously to no avail). 5 3388
int newValue = int.Parse("123");
Regards,
John
int.Parse("42");
You have to think about "what would provide the functionality?" to know where to look as there are no global functions. So what would know what an int is meant to look like as a string? An int! :-)
Regards
Richard Blewett - DevelopMentor http://staff.develop.com/richardb/weblog
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<nr********************@comcast.com>
Kind of a newbie question, but I need to be able to convert a string to
an integer in C#, similar to VB's Val(). Anybody know how to do this?
I've tried C-style casting (obviously to no avail).
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004
[microsoft.public.dotnet.languages.csharp]
Yes Dan...try...
myint = Convert.ToInt16(mystring);
"Dan" <an**@anon.com> wrote in message
news:nr********************@comcast.com... Kind of a newbie question, but I need to be able to convert a string to an integer in C#, similar to VB's Val(). Anybody know how to do this? I've tried C-style casting (obviously to no avail).
Dan <an**@anon.com> wrote: Kind of a newbie question, but I need to be able to convert a string to an integer in C#, similar to VB's Val(). Anybody know how to do this? I've tried C-style casting (obviously to no avail).
Use int.Parse(string) or Convert.ToInt32(string). Various overloads
allow you some different options.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
If you would like to determine whether the string can be parsed into an int,
take a look at the double.TryParse() method. Otherwise, if your string is
input by the user, you'll want to surround it with a try/catch block.
Tom Clement
Apptero, Inc.
"Dan" <an**@anon.com> wrote in message
news:nr********************@comcast.com... Kind of a newbie question, but I need to be able to convert a string to an integer in C#, similar to VB's Val(). Anybody know how to do this? I've tried C-style casting (obviously to no avail). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Krakatioison |
last post by:
My sites navigation is like this:
http://www.newsbackup.com/index.php?n=000000000040900000
, depending on the variable "n" (which is always a number), it will take me
anywhere on the site......
|
by: Stu Cazzo |
last post by:
I have the following:
String myStringArray;
String myString = "98 99 100";
I want to split up myString and put it into myStringArray.
If I use this:
myStringArray = myString.split(" ");
it...
|
by: John F Dutcher |
last post by:
I use code like the following to retrieve fields from a form:
recd =
recd.append(string.ljust(form.getfirst("lname",' '),15))
recd.append(string.ljust(form.getfirst("fname",' '),15))
etc.,...
|
by: Derek Hart |
last post by:
I wish to execute code from a string. The string will have a function name,
which will return a string:
Dim a as string
a = "MyFunctionName(param1, param2)"
I have seen a ton of people...
|
by: Angus Leeming |
last post by:
Hello,
Could someone explain to me why the Standard conveners chose to typedef
std::string rather than derive it from std::basic_string<char, ...>?
The result of course is that it is...
|
by: Andrew |
last post by:
I have written two classes : a String Class based on the book " C++ in
21 days " and a GenericIpClass listed below :
file GenericStringClass.h
// Generic String class
|
by: Locusta |
last post by:
Hello,
I have been struggeling for replacing a string in a string. The snippet
from the program below replaces the <, & and > with the XML equivalent
values.
In the program, I allocate space...
|
by: zoro |
last post by:
Hi,
I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party
string handling library that includes some very useful string
functions, in particular I'm interested in BEFORE (return...
|
by: Emilio |
last post by:
Question about
Shared Sub Connect(server As , message As )
Why is in square brackets?
Is it like
Shared Sub Connect(server() As String, message() As String)
|
by: Badass Scotsman |
last post by:
Hello,
Using VB and ASP,NET I would like to be able to search a STRING for a
smaller STRING within, based on the characters which appear before and
after.
For example:
String1 = " That was...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
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: 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: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
| |