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 8875199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:54:59+00:00 2026-06-14T18:54:59+00:00

I used MyString.Split(Environment.Newline.ToCharArray()[0]) to split my string from a file into different pieces. But,

  • 0

I used MyString.Split(Environment.Newline.ToCharArray()[0]) to split my string from a file into different pieces. But, every item in the array, except the first one starts with \n after I did that? I know the way that I’m splitting by newlines is kind of “cheaty” for lack of a better word, so if there is a better way of doing this, please tell me…

Here is the file…
enter image description here

  • 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-06-14T18:55:00+00:00Added an answer on June 14, 2026 at 6:55 pm

    If you are wanting to maintain using the .Split() instead of reading a file in a line at a time you can do…

    var splitResult = MyString.Split( new string[]{ System.Environment.NewLine },
        System.StringSplitOptions.RemoveEmptyEntries  );
        /* or System.StringSplitOptions.None if you want empty results as well */
    

    EDIT:

    The problem you were having is that in a non-unix environment the new-line “character” is actually two characters. So when you grabbed the zero index you were actually splitting on a carriage return…not the new-line character (\n).

    Windows = “\r\n”

    Unix = “\n”

    Per http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx

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

Sidebar

Related Questions

I have used the excellent gskinner.com/RegExr/ tool to test my string matching regex but
I used the following code to remove script, link tags from my string, $contents='<script>inside
I'm trying to split a utf8 encoded string into an array of chars. The
I used the phonegap website to create an IPA file. Now I want to
lets say I have a string that I want to split based on several
I have always used Replace(myString, vbCrLf, <br/>) to show line breaks when outting something
Well, I want to open pdf file whose name contains certain string. this is
The following code is taken from The iOS 5 Developer's Cookbook used to illustrate
I need to split a string and extract words separated by whitespace characters.The source
i'm having a string(MyString) of length 9700000(approximately). and a for loop to get substring

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.