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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:28:40+00:00 2026-06-17T12:28:40+00:00

string[] lines3 = new string[100]; List<string> lines2 = new List<string>(); lines3 = Regex.Split(s1, @\s*,\s*);

  • 0
string[] lines3 = new string[100];
List<string> lines2 = new List<string>();
lines3 = Regex.Split(s1, @"\s*,\s*");

if (!lines2.Contains(lines3.ToString()))
{
    lines2.AddRange(lines3.Distinct().ToArray());
}

I have checked all the spaces etc but i still get duplicate values in my lines2 List

I have to remove my duplicate values here itself

  • 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-17T12:28:41+00:00Added an answer on June 17, 2026 at 12:28 pm

    Your this check:

    if (!lines2.Contains(lines3.ToString()))
    

    is invalid. You are checking if your lines2 contains System.String[] since lines3.ToString() will give you that. You need to check if item from lines3 exists in lines2 or not.

    You can iterate each item in lines3 check if it exists in the lines2 and then add it. Something like.

    foreach (string str in lines3)
    {
        if (!lines2.Contains(str))
            lines2.Add(str);
    }
    

    Or if your lines2 is any empty list, then you can simply add the lines3 distinct values to the list like:

    lines2.AddRange(lines3.Distinct());
    

    then your lines2 will contain distinct values.

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

Sidebar

Related Questions

I have a String[] LinesFromFile which contains about 100 lines loaded from a file
Given the following string arrray: string[] ranges = new string[]{0-100, 100-200, 500-1000}; I would
I'm relatively new to Python's string handling and have troubles figuring out how to
I've a Java String with new lines(\n), say for example String value = This
The following ignore new lines when I display them private void post() { String
If I have a method like this: public void DoSomething(int Count, string[] Lines) {
I get a string which contains a sentence in two lines : 'hello this
I am new to unix commands. I have a file named server.txt, which has
I have a situation where I'm parsing csv file (100-150 lines at a time
I have a class extracting strings from a large file (100,000) lines and wanted

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.