Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Parsing Problem....

Reply
Thread Tools

Parsing Problem....

 
 
Wallace
Guest
Posts: n/a
 
      04-25-2006
Hai all,

In VC++,

CString str = " 4 76 1";
int nNo = atoi(str.Mid(0,);

it returns nNo = 4 as output.... it returns the first integer
occurence and neglects the remaining character....


Similarly, In C#.NET I do the same as following....

string str = " 4 76 1";
int nNo = int.Parse(str.Substring(0, );

it is throwing the exception as "Input string is not in correct
format....."

How can i get the output as 4(i.e nNo = 4) in c#.net ????
Is there any other function other than parse, to fulfil this??

Please help... Thanx in advance...
Urgent..... Looking forward for the ur response....

 
Reply With Quote
 
 
 
 
Karl Seguin [MVP]
Guest
Posts: n/a
 
      04-25-2006
Well, if the # is always in the format of " # ## #" then you can simply do
something like:

str.Substring(1,1);

if the # format is a little different, but space delimited, I'd split the
string on a space

string[] numbers = str.Split(' ');
numbers[1]; (it's 1 because of the leading space). You could also just
Trim() the str to get rid of those.

If your pattern is any more complexe, I'd recommend using a regular
expression.

Karl

--
http://www.openmymind.net/



"Wallace" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Hai all,
>
> In VC++,
>
> CString str = " 4 76 1";
> int nNo = atoi(str.Mid(0,);
>
> it returns nNo = 4 as output.... it returns the first integer
> occurence and neglects the remaining character....
>
>
> Similarly, In C#.NET I do the same as following....
>
> string str = " 4 76 1";
> int nNo = int.Parse(str.Substring(0, );
>
> it is throwing the exception as "Input string is not in correct
> format....."
>
> How can i get the output as 4(i.e nNo = 4) in c#.net ????
> Is there any other function other than parse, to fulfil this??
>
> Please help... Thanx in advance...
> Urgent..... Looking forward for the ur response....
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What libraries should I use for MIME parsing, XML parsing, and MySQL ? John Levine Ruby 0 02-02-2012 11:15 PM
[ANN] Parsing Tutorial and YARD 1.0: A C++ Parsing Framework Christopher Diggins C++ 0 07-09-2007 09:01 PM
[ANN] Parsing Tutorial and YARD 1.0: A C++ Parsing Framework Christopher Diggins C++ 0 07-09-2007 08:58 PM
SAX Parsing - Weird results when parsing content between tags. Naren XML 0 05-11-2004 07:25 PM
Perl expression for parsing CSV (ignoring parsing commas when in double quotes) GIMME Perl 2 02-11-2004 05:40 PM



Advertisments