|
-
Nov 4th, 2002, 07:14 AM
#1
Thread Starter
Frenzied Member
convert string to int
How is this possible? Anyone has any idea? the type "string" is different than the char* string in C++.
For example, if I have the string "12", and I want it as an int 12
best regards
Henrik
-
Nov 4th, 2002, 09:08 AM
#2
PowerPoster
Because .NET enforces strong typing, converting a string to an int is not a valid conversion operation. I'm not exactly sure there is no way around this, so you many want to play with the System.Convert class. If I was at my computer, I would try for myself..
-
Nov 4th, 2002, 09:25 AM
#3
Thread Starter
Frenzied Member
The thing I am trying to do is to read a line of text from a file...
there I use string.substring() to fetch the parameter I need.
Then I need to upload the info to an SQL db into an int field.
The variable is really a week number, so I really don't want to change the db field. It feels very wrong. I won't do any arithmetics, just basic comparisons with boolean operators.
Anyone with suggestion, please shout!!!!
btw
using System.Convert;
won't work... unknown class...
best regards
Henrik
-
Nov 4th, 2002, 01:26 PM
#4
Addicted Member
here go
Code:
System.Convert.ToInt16(MyString)
Last edited by MasterBlaster; Nov 4th, 2002 at 01:29 PM.
-
Nov 4th, 2002, 01:27 PM
#5
Addicted Member
Originally posted by MrNorth
btw
using System.Convert;
won't work... unknown class...
best regards
Henrik
Then you prolly have other problems post your code
-
Nov 4th, 2002, 02:45 PM
#6
Thread Starter
Frenzied Member
The code is a bit large to post on the forum... but I declare my namespaces like standard procedure:
using System.IO;
using System.String;
etc
etc
It seems like intellisense won't recognize the Convert class as member of System??? Anything I have to add???
Anything I can try?
thansk for the answer btw... 
best regards
Henrik
-
Nov 4th, 2002, 02:49 PM
#7
PowerPoster
You need this:
Code:
using System;
//.... Rest of your code
-
Nov 4th, 2002, 02:54 PM
#8
Thread Starter
Frenzied Member
Solved it
I could just write Convert.whatevermethod();
no namespace declaration was needed.... spoooky 
best regards
Henrik
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|