Jump to content
  • Advertisement
Sign in to follow this  
glBender

[C#] extracting variables from strings

This topic is 4424 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've just started using C#, and I can't seem to figure out how to extract variables from a string. I'm looking for something similar to c++'s sscanf, I guess. When I googled for help, most results were about extracting them manually, which I could take the time to do, but with c#'s huge high level library, I can't imagine there isn't a function designed for just such a purpose already. Any help is appreciated, Bender

Share this post


Link to post
Share on other sites
Advertisement
Most of the numeric class types have Parse methods that you can use to extract values from strings like Double.Parse() or Boolean.Parse()

Share this post


Link to post
Share on other sites
Are you just wanting to read primitive types, like scanf, or something more complicated? (For the primitive types, the last poster already mentioned the solution for that).

OOPS... you responded to him before I posted. Cool, glad you got it working!

Share this post


Link to post
Share on other sites
What I'm actually working on is a routine to load .N3D files, so actually I think I need a little more... N3D files don't explicitly state the number of vertices. Each line containing a vertice starts with a v,('v 0.00000 0.00000 0.00000'). In c++ I would go through the file with sscanf and check the return value, so i knew how many instances there were. I dont really think I can do that with the .parse() functions sicrane was talking about. Any more ideas?

Share this post


Link to post
Share on other sites
Okay, I figured out how to do it now... check if it fits the format 'v float float float' then split the string into 3 others and use float.parse(). Just one question, I googled this and its kind of long so i didnt really find any helpfull answers.




//I have this method
protected void testFunction(string f)
{
}

//If I pass it a string declared like this...

string testString = "Test!";
testFuction(testString);

// It gives me this error

Error 1 An object reference is required for the nonstatic field, method, or property




edit: Sorry I never get my point across lol. I simplified the code so it shows what i mean...

[Edited by - glBender on July 9, 2006 12:39:26 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!