Tinkr2/4.2/AphelionCore/AphelionCore/Helpers/Strings.cs
/// <summary>
/// Splits a string by delimiter while accounting for quotes
/// </summary>
/// <param name="value">String to split</param>
/// <param name="delimiter">Character to split by</param>
/// <returns>Returns the splitted string</returns>
Splits a string by delimiter while accounting for quotes
Splits a string by delimiter while accounting for quotes
public static string[] SplitComponents(string value, char delimiter)
      {
         int iStart = 0;
         string[] ret = null;
         while (true)
         {
            int i = value.IndexOf(delimiter, iStart);
            if (InQuotes(value, i))
            {
               iStart = i + 1;
            }
            else
            {
               string s;
               if (i < 0)
               {
                  s = value;
               }
               else
               {
                  s = value.Substring(0, i).Trim();
                  value = value.Substring(i + 1);
               }
               if (ret == null)
               {
                  ret = new[] { s };
               }
               else
               {
                  var tmp = new string[ret.Length + 1];
                  Array.Copy(ret, tmp, ret.Length);
                  tmp[tmp.Length - 1] = s;
                  ret = tmp;
               }
               iStart = 0;
            }
            if (i < 0 || value == string.Empty)
            {
               break;
            }
         }
         return ret;
      }
public static string [ ] SplitComponents ( string value , char delimiter ) { int iStart = 0 ; string [ ] ret = null ; while ( true ) { int i = value . IndexOf ( delimiter , iStart ) ; if ( InQuotes ( value , i ) ) { iStart = i + 1 ; } else { string s ; if ( i < 0 ) { s = value ; } else { s = value . Substring ( 0 , i ) . Trim ( ) ; value = value . Substring ( i + 1 ) ; } if ( ret == null ) { ret = new [ ] { s } ; } else { var tmp = new string [ ret . Length + 1 ] ; Array . Copy ( ret , tmp , ret . Length ) ; tmp [ tmp . Length - 1 ] = s ; ret = tmp ; } iStart = 0 ; } if ( i < 0 || value == string . Empty ) { break ; } } return ret ; }
Splits a string by delimiter while accounting for quotes
Splits a string by delimiter while accounting for quotes
// Find delimiter // Separate value // Add value // Break on last value
Returns the splitted string
Returns the splitted string
value
string
String to split
String to split
delimiter
char
Character to split by
Character to split by