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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:15:23+00:00 2026-06-09T10:15:23+00:00

I am trying to split some string on the basis of newline character ‘\n’

  • 0

I am trying to split some string on the basis of newline character ‘\n’

I have this delimiter stored in resx file as:

Name: RecordDelimiter
Value: \n

When I retrieve this value from .resx file it is always returned as ‘\n’ and
split function does not return accurate results.
However when I try with string “\n”, it’s working fine

Here is my code –

private static void GetRecords()
{
    string recordDelimiter = @"\n";
    string recordDelimiter1 = "\n"; // only this returns correct result
    string recordDelimiter2 = ResourceFile.RecordDelimiter; //from resx file, returns \\n :-(
    string recordDelimiter3 = ResourceFile.RecordDelimiter.Replace("\\", @"\"); //try replacing \\n with \n

    string fileOutput = "aaa, bbb, ccc\naaa1, bbb1, ccc1\naaa2, bbb2, ccc2";

    string[] records = fileOutput.Split(new string[] { recordDelimiter }, StringSplitOptions.None);
    string[] records1 = fileOutput.Split(new string[] { recordDelimiter1 }, StringSplitOptions.None);
    string[] records2 = fileOutput.Split(new string[] { recordDelimiter2 }, StringSplitOptions.None);
    string[] records3 = fileOutput.Split(new string[] { recordDelimiter3 }, StringSplitOptions.None);

    int recordCount = records.Count();  //returns 1
    int recordCount1 = records1.Count();  //returns 3 -- only this returns correct result
    int recordCount2 = records2.Count();  //returns 1
    int recordCount3 = records3.Count();  //returns 1
}

I want to keep the delimiter in resx file.
Can anyone please guide if I am missing something?

Thank you!

  • 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-09T10:15:25+00:00Added an answer on June 9, 2026 at 10:15 am

    The reason your second method is the only one returning the correct result is that it is the only one where the delimiter is the new line character. “\n” is just a representation of the newline character in C#, and @”\n” is the literal string of a slash followed by the letter n. In other words @”\n” != “\n”.

    So if you wanted to store the delimiter character in resx, you would need to show us the code of how you are storing it there. Currently it seems to just be stord as a literal string, and not the actual control characters.

    One (very rough) fix would be to take the string from the Resources and call .Replace(@”\n”, “\n”) depending on what exactly is stored in the file. I will update my answer if/when I find a better solution, or once you have updated your question.

    EDIT:

    Ok, found a somewhat gimmicky solution. The core problem is how do you write just \n, correct? Well, I made a test project, with a textbox and the following code:

    this.textBox1.Text = "1\n2";
    

    Fire up this project, select all of the text in the textbox, and copy to clipboard. Then go to your real project’s resources, and paste the value from your clipboard. Then carefully delete the numbers from around the control character. And there you go, \n control character in a resource string. (The reason for the numbers was that it wasn’t possible to select only the control character from the textbox.)

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

Sidebar

Related Questions

I am trying to split the string in a file based on some delimiter.But
I have a string: [\n['-','some text what\rcontains\nnewlines'],\n\n trying to parse: Regex.Split(@[\n['-','some text what contains
I am trying to read file and split its line to get some context(Computer
Trying to split this string 主楼怎么走 into separate characters (I need an array) using
Using Ruby, I'm trying to parse some documentation in which I need to split
I am trying to split a string in javascript . it works fine in
I'm trying to split strings in C# like this COMMSTR1-NAC-NAM-P-C FCPANAM1-NAC-NAM-P-C CHAZEL1-NAT-CBM-P-C should be
I'm trying to split an app.config file into multiple files to make it easier
I'm trying to split an HTML string by a token in order to create
I am trying to use splitOn function in haskell to split a string based

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.