Taking a special substring

This is a discussion on Taking a special substring within the C# Programming forums, part of the General Programming Boards category; Hi everyone ! I'm still trying to do that simple parser with C#. I was wondering if there is an ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    53

    Taking a special substring

    Hi everyone ! I'm still trying to do that simple parser with C#. I was wondering if there is an easy way to take a substring out of another. I'd need to take every characters that form a number and put them together and form my number.
    Ex: 1234 + 5678
    Would store 1234 and 5678 so I can reuse them later.

  2. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    53
    Ok, I've found out how to do it, but how do I tell the compilator that I will need an unknown number of strings ?
    Here's the function's code:
    Code:
    public static void GetNumbers( )
    {
    	string[] temp = new string[ 3 ] ;
    	temp = Maths.IO.GetEquation( ).Split( ' ' ) ;
    	for( int i = 0 ; i < temp.Length ; ++i )
    		if( temp[i] != "+" && temp[i] != "-" && temp[i] != "*" && temp[i] != "/" )
    			Numbers.Add( temp[i] ) ;
    }

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    If you have an unknown quantity, you need a collection, not an array. You can use generic collections like ArrayList that store objects, or you can save yourself a lot of casting to and from string and use System.Collections.Specialized.StringCollection.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. split string and remove substring
    By nyc_680 in forum C Programming
    Replies: 3
    Last Post: 03-02-2009, 03:45 AM
  2. I need help with creating a substring program
    By CProgramingBegg in forum C Programming
    Replies: 9
    Last Post: 02-06-2009, 08:50 AM
  3. longest common substring problem
    By Enchanter88 in forum C++ Programming
    Replies: 4
    Last Post: 09-29-2007, 11:02 AM
  4. Replacing a substring with another
    By Dan17 in forum C Programming
    Replies: 3
    Last Post: 09-14-2006, 10:37 AM
  5. Please help me
    By teedee46 in forum C++ Programming
    Replies: 9
    Last Post: 05-06-2002, 11:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21