none
Cant split by .Split(">>>") - Error message telling me a I need a char in the brackets RRS feed

  • Question

  • using System;
    using System.Collections.Generic;
    using System.Linq;

    public class Program
    {
    public static void Main()
    {
    string text = "Hello>>>agsdg>>>hdfhdf>>>shsdhsd";

            string[] words = text.Split(">>>");

    Console.ReadLine();
    }


    }

    When I try to run this code it tells me i need to split using only a char and it cannot split by a string.
    I searched for the split function and a microsoft guide shows it can split by a string with the same syntax I used.
    I think it is something on my end maybe region or different settings. I have tried to change the region and re install the visual studio however it does not help.
    Saturday, April 4, 2020 9:21 AM

All replies

  • You may be referring to this overload of the Split method:

    https://docs.microsoft.com/en-us/dotnet/api/system.string.split?view=netframework-4.8#System_String_Split_System_String___System_StringSplitOptions_

    Observe that it doesn't take a string, but an array of strings.

    string[] words = text.Split(new string[]{">>>"}, StringSplitOptions.None);

    • Proposed as answer by cheong00Editor Saturday, April 4, 2020 12:37 PM
    Saturday, April 4, 2020 9:37 AM
    Moderator
  • Hello,

    Try this out

    string text = "Hello>>>agsdg>>>hdfhdf>>>shsdhsd";
    string[] words = text.Replace(">>>", "-").Split('-');


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Saturday, April 4, 2020 9:44 AM
    Moderator
  • Hi,

    It seems that your problem has been solved. If so, please click "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, April 9, 2020 8:57 AM