none
how can i split a string which doesn't start with a number

    Question

  • how can i split a comma separated string which does not start with a number 

    string is in this format( MANUFACTUREFORM,0,1,1,1,CATEGORYFORM,1,0,1,1)

    Monday, October 07, 2013 6:52 AM

Answers

  • Hi, you can use String.Split(','); then you will get back an array of all the substrings.
    Monday, October 07, 2013 7:03 AM
  • you requirements are not clear, Do you need to get the sentences between commas? do you need to check if a word doesn't have a number in its beginning?

    Anyway, I think "J Chase" is right you can use Split(',') to get array of strings and work on it. If you need to exclude words with numbers in its beginning, you can use Regular Expression i.e

                string input = "MANUFACTUREFORM,0,1,1,1,CATEGORYFORM,1,0,1,1";
                string[] inputs = input.Split(',');
                for (int i = 0; i < inputs.Length; i++)
                {
                    var reg = new Regex(@"^\d+"); // Check if there is any numbers in the beginning of the word.
                    MatchCollection macthes = reg.Matches(inputs[i]);
                    if (macthes.Count == 0)
                    {
                        // add code to handle the string values.
                    }
                }

     

    Please remember to 'Mark as Answer' the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, October 07, 2013 9:38 AM

All replies

  • Hi, you can use String.Split(','); then you will get back an array of all the substrings.
    Monday, October 07, 2013 7:03 AM
  • the above string value is not the same as it is so cannot use a substring
    Monday, October 07, 2013 7:06 AM
  • Sorry I'm not sure what you mean. Can you post your code?
    Monday, October 07, 2013 7:07 AM
  • string str = "MANUFACTUREFORM,0,1,1,1,CATEGORYFORM,1,0,1,1";
                var splitString = str.Split(',');
                foreach (var s in splitString)
                {
                    Console.Write(s);
                }


    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Monday, October 07, 2013 9:37 AM
  • you requirements are not clear, Do you need to get the sentences between commas? do you need to check if a word doesn't have a number in its beginning?

    Anyway, I think "J Chase" is right you can use Split(',') to get array of strings and work on it. If you need to exclude words with numbers in its beginning, you can use Regular Expression i.e

                string input = "MANUFACTUREFORM,0,1,1,1,CATEGORYFORM,1,0,1,1";
                string[] inputs = input.Split(',');
                for (int i = 0; i < inputs.Length; i++)
                {
                    var reg = new Regex(@"^\d+"); // Check if there is any numbers in the beginning of the word.
                    MatchCollection macthes = reg.Matches(inputs[i]);
                    if (macthes.Count == 0)
                    {
                        // add code to handle the string values.
                    }
                }

     

    Please remember to 'Mark as Answer' the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, October 07, 2013 9:38 AM