Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7650425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:14:57+00:00 2026-05-31T11:14:57+00:00

How can I split the following string on \ and/or / using LINQ I

  • 0

How can I split the following string on “\” and/or “/” using LINQ

I say and/or for “\” and “/” because in my file paths, I might end up getting forward slashes only, backslashes only or a mix of both.

 "temp\\SimpleRec/bin/Debug/Geming.SimpleRec.vshost.exe"

 "temp\\SimpleRec\\bin\\Debug\\Geming.SimpleRec.vshost.exe"

 "temp/SimpleRec/bin/Debug/Geming.SimpleRec.vshost.exe"

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:14:59+00:00Added an answer on May 31, 2026 at 11:14 am

    String.Split() seems to be the best option here, but just for fun it is also possible to do with LINQ.

    One of my implementations of String Calculator Kata uses this approach (no Split at all). See InternalAdd() method. I took functional approach with head and tail. You divide string to head and tail using .Take() and return head + recursive result of calling the same function for tail.

    Sample code for one char delimiter is below (things are getting complicated when delimiters are getting longer):

        private IEnumerable<string> BreakString(string source)
        {
            var delimiter = '/';
            var head = source.TakeWhile(c => c != delimiter);
            if (!head.Any())
            {
                yield break;
            }
            var tail = source.SkipWhile(c => c != delimiter)
                .Skip(1);
            yield return String.Join("", head);
            foreach (var t in BreakString(String.Join("", tail)))
            {
                yield return t;
            }
    
        }
    
    
    // usage
    from s in BreakString(source)
    

    You can also go further and get rid of String.Join() by tail.Aggregate(new StringBuilder(), (sb, c) => sb.Append(c)).ToString();

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the following code, I can download the HTML of a file from the
I'd like to String.Split() the following string using a comma as the delimitter: John,Smith,123
How can i split the following string into Key-Value Pair / Hash table ...
Referring to this topic: Minimize LINQ string token counter And using the following provided
How can I split long commands over multiple lines in a batch file?
How can I split a String by Unicode range in Ruby. I wanted to
How can I split a string such as Mar10 into Mar and 10 in
I am doing a home work question to split a string without using the
I'm getting a string similar to the following back from the database: The object
I have the following String: (X,Y,Z),(A,B,C),(R,S,T) I want to split this into a multi-dimensional

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.