Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Delimiter Split

    Hello,

    The string.Split method is very useful for splitting
    strings that use a single character as a delimiter. i.e.:

    string str = "First;Second;Third";

    string[] strArray = str.Split(new char[] {';'});

    But I am having trouble getting the Split method to split
    a string with a delimiter of more than one character.
    What is the correct syntax?

    string str = "First<;>Second<;>Third";

    // This does not work, it gives an "Unhandled Exception
    // of type 'System.ExecutionEngineException' in
    // mscorlib.dll"
    string[] strArray = str.Split(new char[] {'<',';','>'});

    Thanks!
    Mark Fox Guest

  2. Similar Questions and Discussions

    1. #39306 [NEW]: Changing Delimiter
      From: ctingley at mediagrids dot com Operating system: Windows PHP version: 5.1.6 PHP Bug Type: MySQL related Bug...
    2. Delimiter for string..
      Friends, I am running a perl script as below which is working perfectly and want to replace the hardcoded values with variables. (the script...
    3. Splitting and keeping the delimiter
      Hello! I have a string like this: 12.00 Simpsons 12.30 Seinfeld 13.00 Movie: Dante's Peak And I want to split that in seperate "programs" that...
    4. Delimiter WITHOUT lots of IF's
      Hi all, I need to create an automatic process for visitors who are adding items into a shopping cart, be able to see how many MBs and how many...
    5. Regex help (? as delimiter)
      Lawrence Tierney wrote: --------------^ No it doesn't. Exchange \d for \w and it matches. -- Gunnar Hjalmarsson
  3. #2

    Default Re: Delimiter Split

    Hi,

    the relationship between chars is OR and not AND.
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/h[/url]
    tml/frlrfsystemstringclasssplittopic1.asp



    Natty Gur, CTO
    Dao2Com Ltd.
    34th Elkalay st. Raanana
    Israel , 43000
    Phone Numbers:
    Office: +972-(0)9-7740261
    Fax: +972-(0)9-7740261
    Mobile: +972-(0)58-888377


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

  4. #3

    Default Re: Delimiter Split

    "Mark Fox" <info@solelsoftware.com> wrote in
    news:026901c35f98$5abb7c10$a101280a@phx.gbl:
    > Hello,
    >
    > The string.Split method is very useful for splitting
    > strings that use a single character as a delimiter. i.e.:
    >
    > string str = "First;Second;Third";
    >
    > string[] strArray = str.Split(new char[] {';'});
    >
    > But I am having trouble getting the Split method to split
    > a string with a delimiter of more than one character.
    > What is the correct syntax?
    >
    > string str = "First<;>Second<;>Third";
    >
    > // This does not work, it gives an "Unhandled Exception
    > // of type 'System.ExecutionEngineException' in
    > // mscorlib.dll"
    > string[] strArray = str.Split(new char[] {'<',';','>'});
    Mark,

    To split on multiple characters, use the Regex.Split method:

    using System.Text.RegularExpressions;

    ...

    string str = "First<;>Second<;>Third";
    string[] strArray = Regex.Split(str, "<;>");


    Hope this helps.

    Chris.
    -------------
    C.R. Timmons Consulting, Inc.
    [url]http://www.crtimmonsinc.com/[/url]
    Chris R. Timmons Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139