Parse String Lines - CSharp System

CSharp examples for System:String Parse

Description

Parse String Lines

Demo Code

// BitCollectors Plink Service is free software: you can redistribute it and/or 
using System.Text.RegularExpressions;
using System.Collections.Specialized;
using System;//from   w  ww.  j av a 2s . c o m

public class Main{
        public static string[] ParseStringLines(string text, string commentIndicator = "#")
        {
            string[] stringLines = text.Split('\n');
            StringCollection stringCollection = new StringCollection();

            foreach (string line in stringLines)
            {
                string newLine = line.Trim();

                if (line.Contains(commentIndicator))
                {
                    string[] splitLine = line.Split(new[] { commentIndicator }, StringSplitOptions.None);
                    newLine = splitLine[0];
                }

                if (newLine.Trim().Length > 0 && validateTunnelString.IsMatch(newLine.Trim()))
                {
                    stringCollection.Add(newLine.Trim());
                }
            }

            string[] returnValue = new string[stringCollection.Count];

            stringCollection.CopyTo(returnValue, 0);

            return returnValue;
        }
}

Related Tutorials