Get all unique values out of strings
I am facing some problems while getting unique values out of string
s.
Example:
string1 = "4,5"
string2 = "7,9"
string3 = "4,7,6,1"
string4 = "1"
After I need to get all unique values as an int
. In this case result must be 6. But each time the number of strings can change.
Is this even possible?
c# .net string
|
show 1 more comment
I am facing some problems while getting unique values out of string
s.
Example:
string1 = "4,5"
string2 = "7,9"
string3 = "4,7,6,1"
string4 = "1"
After I need to get all unique values as an int
. In this case result must be 6. But each time the number of strings can change.
Is this even possible?
c# .net string
What did you mean byunique value
?
– Saif
Nov 22 '18 at 6:34
2
do some research onlinq
anddistinct
– JohnB
Nov 22 '18 at 6:35
He probably means distinct values.
– Uwe Keim
Nov 22 '18 at 6:35
No I guess OP want value whereoccurrence is one
– Prasad Telkikar
Nov 22 '18 at 6:37
OP wants to get adistinct
list of numbers i believe - ie no duplicates
– JohnB
Nov 22 '18 at 6:38
|
show 1 more comment
I am facing some problems while getting unique values out of string
s.
Example:
string1 = "4,5"
string2 = "7,9"
string3 = "4,7,6,1"
string4 = "1"
After I need to get all unique values as an int
. In this case result must be 6. But each time the number of strings can change.
Is this even possible?
c# .net string
I am facing some problems while getting unique values out of string
s.
Example:
string1 = "4,5"
string2 = "7,9"
string3 = "4,7,6,1"
string4 = "1"
After I need to get all unique values as an int
. In this case result must be 6. But each time the number of strings can change.
Is this even possible?
c# .net string
c# .net string
edited Nov 22 '18 at 10:49
Dmitry Bychenko
112k1099141
112k1099141
asked Nov 22 '18 at 6:31
EdgarsEdgars
1
1
What did you mean byunique value
?
– Saif
Nov 22 '18 at 6:34
2
do some research onlinq
anddistinct
– JohnB
Nov 22 '18 at 6:35
He probably means distinct values.
– Uwe Keim
Nov 22 '18 at 6:35
No I guess OP want value whereoccurrence is one
– Prasad Telkikar
Nov 22 '18 at 6:37
OP wants to get adistinct
list of numbers i believe - ie no duplicates
– JohnB
Nov 22 '18 at 6:38
|
show 1 more comment
What did you mean byunique value
?
– Saif
Nov 22 '18 at 6:34
2
do some research onlinq
anddistinct
– JohnB
Nov 22 '18 at 6:35
He probably means distinct values.
– Uwe Keim
Nov 22 '18 at 6:35
No I guess OP want value whereoccurrence is one
– Prasad Telkikar
Nov 22 '18 at 6:37
OP wants to get adistinct
list of numbers i believe - ie no duplicates
– JohnB
Nov 22 '18 at 6:38
What did you mean by
unique value
?– Saif
Nov 22 '18 at 6:34
What did you mean by
unique value
?– Saif
Nov 22 '18 at 6:34
2
2
do some research on
linq
and distinct
– JohnB
Nov 22 '18 at 6:35
do some research on
linq
and distinct
– JohnB
Nov 22 '18 at 6:35
He probably means distinct values.
– Uwe Keim
Nov 22 '18 at 6:35
He probably means distinct values.
– Uwe Keim
Nov 22 '18 at 6:35
No I guess OP want value where
occurrence is one
– Prasad Telkikar
Nov 22 '18 at 6:37
No I guess OP want value where
occurrence is one
– Prasad Telkikar
Nov 22 '18 at 6:37
OP wants to get a
distinct
list of numbers i believe - ie no duplicates– JohnB
Nov 22 '18 at 6:38
OP wants to get a
distinct
list of numbers i believe - ie no duplicates– JohnB
Nov 22 '18 at 6:38
|
show 1 more comment
6 Answers
6
active
oldest
votes
Use Split
and Distinct
var input = "1,3,1,2,3,43,23,54,3,4";
var result input.Split(',')
.Distinct();
Console.WriteLine(string.Join(",",result));
Output
1,3,2,43,23,54,4
Full Demo Here
Additional Resources
String.Split Method
Returns a string array that contains the substrings in this instance
that are delimited by elements of a specified string or Unicode
character array.
Enumerable.Distinct Method
Returns distinct elements from a sequence.
and if you're OCD,OrderBy
...
– JohnB
Nov 22 '18 at 6:40
@JohnB OCD indeed :)
– Michael Randall
Nov 22 '18 at 6:44
add a comment |
If "number of strings can change", let's organize them into a collection:
List<string> strings = new List<string> {
"4,5",
"7,9",
"4,7,6,1",
"1"
};
Then we can right a simple Linq:
var uniques = strings
.SelectMany(item => item.Split(',')) // split each item and flatten the result
.Select(item => int.Parse(item))
.Distinct()
.ToArray(); // let's have an array of distinct items: {4, 5, 7, 9, 6, 1}
If you want to obtain items which appears just once:
var uniques = strings
.SelectMany(item => item.Split(',')) // split each item and flatten the result
.Select(item => int.Parse(item))
.GroupBy(item => item)
.Where(item => item.Count() == 1)
.Select(group => group.Key)
.ToArray(); // let's have an array of items which appear once: {5, 9, 6}
I like this approach upvote, also i need to use my upvotes for the day
– Michael Randall
Nov 22 '18 at 7:03
Last one is awesome,+1
– Prasad Telkikar
Nov 22 '18 at 7:06
add a comment |
Instead of using number of string variable you can you single instance of
StringBuilder
Convert all element to array of integer.
Get Distinct/number which comes only one once by Linq
Something like this:
StringBuilder sb = new StringBuilder();
sb.Append("5,5");
sb.Append(",");
sb.Append("7,9");
sb.Append(",");
sb.Append("4,7,6,1");
sb.Append(",");
sb.Append("1");
string arr = sb.ToString().Split(',');
int test = Array.ConvertAll(arr, s => int.Parse(s));
var count = test
.GroupBy(e => e)
.Where(e => e.Count() == 1)
.Select(e => e.First()).ToList();
output:
9
4
6
POC: .netFiddler
add a comment |
A single line can do the job
string s = "1,3,1,2,3,43,23,54,3,4";
string StrArry = s.Split(',');
int IntArry = Array.ConvertAll(StrArry, int.Parse).Distinct().ToArray();
output
1,3,2,43,23,54,4
add a comment |
He can you try this out
var string1 = "4,5";
var string2 = "7,9";
var string3 = "4,7,6,1";
var string4 = "1";
var allStrings = string1 + ',' + string2 + ',' + string3 + ','+ string4;
var distinctNumbers = new List<string>(allStrings.Split(',').Distinct());
Output :
4
5
7
9
6
1
distinctNumbers = Count = 6
add a comment |
This is a longer one than the others, but it might be easier to understand how it works.
List<string> str = new List<string> {"1", "3", "1", "2", "3", "43", "23", "54", "3"," "4 };
List<string> foundstr = new List<string> { };
foreach (string check in str)
{
bool found = false;
//going through every single item in the list and checking if it is found in there
for (int i = 0; i < foundstr.Count; i++)
{
//if found then make found(bool) true so we don't put it in the list
if(check == foundstr[i])
{
found = true;
}
}
//checking if the string has been found and if not then add to list
if(found == false)
{
foundstr.Add(check);
}
}
foreach(string strings in foundstr)
{
Console.WriteLine(strings);
}
Console.ReadLine();
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425077%2fget-all-unique-values-out-of-strings%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use Split
and Distinct
var input = "1,3,1,2,3,43,23,54,3,4";
var result input.Split(',')
.Distinct();
Console.WriteLine(string.Join(",",result));
Output
1,3,2,43,23,54,4
Full Demo Here
Additional Resources
String.Split Method
Returns a string array that contains the substrings in this instance
that are delimited by elements of a specified string or Unicode
character array.
Enumerable.Distinct Method
Returns distinct elements from a sequence.
and if you're OCD,OrderBy
...
– JohnB
Nov 22 '18 at 6:40
@JohnB OCD indeed :)
– Michael Randall
Nov 22 '18 at 6:44
add a comment |
Use Split
and Distinct
var input = "1,3,1,2,3,43,23,54,3,4";
var result input.Split(',')
.Distinct();
Console.WriteLine(string.Join(",",result));
Output
1,3,2,43,23,54,4
Full Demo Here
Additional Resources
String.Split Method
Returns a string array that contains the substrings in this instance
that are delimited by elements of a specified string or Unicode
character array.
Enumerable.Distinct Method
Returns distinct elements from a sequence.
and if you're OCD,OrderBy
...
– JohnB
Nov 22 '18 at 6:40
@JohnB OCD indeed :)
– Michael Randall
Nov 22 '18 at 6:44
add a comment |
Use Split
and Distinct
var input = "1,3,1,2,3,43,23,54,3,4";
var result input.Split(',')
.Distinct();
Console.WriteLine(string.Join(",",result));
Output
1,3,2,43,23,54,4
Full Demo Here
Additional Resources
String.Split Method
Returns a string array that contains the substrings in this instance
that are delimited by elements of a specified string or Unicode
character array.
Enumerable.Distinct Method
Returns distinct elements from a sequence.
Use Split
and Distinct
var input = "1,3,1,2,3,43,23,54,3,4";
var result input.Split(',')
.Distinct();
Console.WriteLine(string.Join(",",result));
Output
1,3,2,43,23,54,4
Full Demo Here
Additional Resources
String.Split Method
Returns a string array that contains the substrings in this instance
that are delimited by elements of a specified string or Unicode
character array.
Enumerable.Distinct Method
Returns distinct elements from a sequence.
edited Nov 22 '18 at 6:43
answered Nov 22 '18 at 6:39
Michael RandallMichael Randall
36.8k84069
36.8k84069
and if you're OCD,OrderBy
...
– JohnB
Nov 22 '18 at 6:40
@JohnB OCD indeed :)
– Michael Randall
Nov 22 '18 at 6:44
add a comment |
and if you're OCD,OrderBy
...
– JohnB
Nov 22 '18 at 6:40
@JohnB OCD indeed :)
– Michael Randall
Nov 22 '18 at 6:44
and if you're OCD,
OrderBy
...– JohnB
Nov 22 '18 at 6:40
and if you're OCD,
OrderBy
...– JohnB
Nov 22 '18 at 6:40
@JohnB OCD indeed :)
– Michael Randall
Nov 22 '18 at 6:44
@JohnB OCD indeed :)
– Michael Randall
Nov 22 '18 at 6:44
add a comment |
If "number of strings can change", let's organize them into a collection:
List<string> strings = new List<string> {
"4,5",
"7,9",
"4,7,6,1",
"1"
};
Then we can right a simple Linq:
var uniques = strings
.SelectMany(item => item.Split(',')) // split each item and flatten the result
.Select(item => int.Parse(item))
.Distinct()
.ToArray(); // let's have an array of distinct items: {4, 5, 7, 9, 6, 1}
If you want to obtain items which appears just once:
var uniques = strings
.SelectMany(item => item.Split(',')) // split each item and flatten the result
.Select(item => int.Parse(item))
.GroupBy(item => item)
.Where(item => item.Count() == 1)
.Select(group => group.Key)
.ToArray(); // let's have an array of items which appear once: {5, 9, 6}
I like this approach upvote, also i need to use my upvotes for the day
– Michael Randall
Nov 22 '18 at 7:03
Last one is awesome,+1
– Prasad Telkikar
Nov 22 '18 at 7:06
add a comment |
If "number of strings can change", let's organize them into a collection:
List<string> strings = new List<string> {
"4,5",
"7,9",
"4,7,6,1",
"1"
};
Then we can right a simple Linq:
var uniques = strings
.SelectMany(item => item.Split(',')) // split each item and flatten the result
.Select(item => int.Parse(item))
.Distinct()
.ToArray(); // let's have an array of distinct items: {4, 5, 7, 9, 6, 1}
If you want to obtain items which appears just once:
var uniques = strings
.SelectMany(item => item.Split(',')) // split each item and flatten the result
.Select(item => int.Parse(item))
.GroupBy(item => item)
.Where(item => item.Count() == 1)
.Select(group => group.Key)
.ToArray(); // let's have an array of items which appear once: {5, 9, 6}
I like this approach upvote, also i need to use my upvotes for the day
– Michael Randall
Nov 22 '18 at 7:03
Last one is awesome,+1
– Prasad Telkikar
Nov 22 '18 at 7:06
add a comment |
If "number of strings can change", let's organize them into a collection:
List<string> strings = new List<string> {
"4,5",
"7,9",
"4,7,6,1",
"1"
};
Then we can right a simple Linq:
var uniques = strings
.SelectMany(item => item.Split(',')) // split each item and flatten the result
.Select(item => int.Parse(item))
.Distinct()
.ToArray(); // let's have an array of distinct items: {4, 5, 7, 9, 6, 1}
If you want to obtain items which appears just once:
var uniques = strings
.SelectMany(item => item.Split(',')) // split each item and flatten the result
.Select(item => int.Parse(item))
.GroupBy(item => item)
.Where(item => item.Count() == 1)
.Select(group => group.Key)
.ToArray(); // let's have an array of items which appear once: {5, 9, 6}
If "number of strings can change", let's organize them into a collection:
List<string> strings = new List<string> {
"4,5",
"7,9",
"4,7,6,1",
"1"
};
Then we can right a simple Linq:
var uniques = strings
.SelectMany(item => item.Split(',')) // split each item and flatten the result
.Select(item => int.Parse(item))
.Distinct()
.ToArray(); // let's have an array of distinct items: {4, 5, 7, 9, 6, 1}
If you want to obtain items which appears just once:
var uniques = strings
.SelectMany(item => item.Split(',')) // split each item and flatten the result
.Select(item => int.Parse(item))
.GroupBy(item => item)
.Where(item => item.Count() == 1)
.Select(group => group.Key)
.ToArray(); // let's have an array of items which appear once: {5, 9, 6}
edited Nov 22 '18 at 7:01
answered Nov 22 '18 at 6:55
Dmitry BychenkoDmitry Bychenko
112k1099141
112k1099141
I like this approach upvote, also i need to use my upvotes for the day
– Michael Randall
Nov 22 '18 at 7:03
Last one is awesome,+1
– Prasad Telkikar
Nov 22 '18 at 7:06
add a comment |
I like this approach upvote, also i need to use my upvotes for the day
– Michael Randall
Nov 22 '18 at 7:03
Last one is awesome,+1
– Prasad Telkikar
Nov 22 '18 at 7:06
I like this approach upvote, also i need to use my upvotes for the day
– Michael Randall
Nov 22 '18 at 7:03
I like this approach upvote, also i need to use my upvotes for the day
– Michael Randall
Nov 22 '18 at 7:03
Last one is awesome,+1
– Prasad Telkikar
Nov 22 '18 at 7:06
Last one is awesome,+1
– Prasad Telkikar
Nov 22 '18 at 7:06
add a comment |
Instead of using number of string variable you can you single instance of
StringBuilder
Convert all element to array of integer.
Get Distinct/number which comes only one once by Linq
Something like this:
StringBuilder sb = new StringBuilder();
sb.Append("5,5");
sb.Append(",");
sb.Append("7,9");
sb.Append(",");
sb.Append("4,7,6,1");
sb.Append(",");
sb.Append("1");
string arr = sb.ToString().Split(',');
int test = Array.ConvertAll(arr, s => int.Parse(s));
var count = test
.GroupBy(e => e)
.Where(e => e.Count() == 1)
.Select(e => e.First()).ToList();
output:
9
4
6
POC: .netFiddler
add a comment |
Instead of using number of string variable you can you single instance of
StringBuilder
Convert all element to array of integer.
Get Distinct/number which comes only one once by Linq
Something like this:
StringBuilder sb = new StringBuilder();
sb.Append("5,5");
sb.Append(",");
sb.Append("7,9");
sb.Append(",");
sb.Append("4,7,6,1");
sb.Append(",");
sb.Append("1");
string arr = sb.ToString().Split(',');
int test = Array.ConvertAll(arr, s => int.Parse(s));
var count = test
.GroupBy(e => e)
.Where(e => e.Count() == 1)
.Select(e => e.First()).ToList();
output:
9
4
6
POC: .netFiddler
add a comment |
Instead of using number of string variable you can you single instance of
StringBuilder
Convert all element to array of integer.
Get Distinct/number which comes only one once by Linq
Something like this:
StringBuilder sb = new StringBuilder();
sb.Append("5,5");
sb.Append(",");
sb.Append("7,9");
sb.Append(",");
sb.Append("4,7,6,1");
sb.Append(",");
sb.Append("1");
string arr = sb.ToString().Split(',');
int test = Array.ConvertAll(arr, s => int.Parse(s));
var count = test
.GroupBy(e => e)
.Where(e => e.Count() == 1)
.Select(e => e.First()).ToList();
output:
9
4
6
POC: .netFiddler
Instead of using number of string variable you can you single instance of
StringBuilder
Convert all element to array of integer.
Get Distinct/number which comes only one once by Linq
Something like this:
StringBuilder sb = new StringBuilder();
sb.Append("5,5");
sb.Append(",");
sb.Append("7,9");
sb.Append(",");
sb.Append("4,7,6,1");
sb.Append(",");
sb.Append("1");
string arr = sb.ToString().Split(',');
int test = Array.ConvertAll(arr, s => int.Parse(s));
var count = test
.GroupBy(e => e)
.Where(e => e.Count() == 1)
.Select(e => e.First()).ToList();
output:
9
4
6
POC: .netFiddler
edited Nov 22 '18 at 6:56
answered Nov 22 '18 at 6:39
Prasad TelkikarPrasad Telkikar
2,260522
2,260522
add a comment |
add a comment |
A single line can do the job
string s = "1,3,1,2,3,43,23,54,3,4";
string StrArry = s.Split(',');
int IntArry = Array.ConvertAll(StrArry, int.Parse).Distinct().ToArray();
output
1,3,2,43,23,54,4
add a comment |
A single line can do the job
string s = "1,3,1,2,3,43,23,54,3,4";
string StrArry = s.Split(',');
int IntArry = Array.ConvertAll(StrArry, int.Parse).Distinct().ToArray();
output
1,3,2,43,23,54,4
add a comment |
A single line can do the job
string s = "1,3,1,2,3,43,23,54,3,4";
string StrArry = s.Split(',');
int IntArry = Array.ConvertAll(StrArry, int.Parse).Distinct().ToArray();
output
1,3,2,43,23,54,4
A single line can do the job
string s = "1,3,1,2,3,43,23,54,3,4";
string StrArry = s.Split(',');
int IntArry = Array.ConvertAll(StrArry, int.Parse).Distinct().ToArray();
output
1,3,2,43,23,54,4
answered Nov 22 '18 at 7:12
SaifSaif
1,1741825
1,1741825
add a comment |
add a comment |
He can you try this out
var string1 = "4,5";
var string2 = "7,9";
var string3 = "4,7,6,1";
var string4 = "1";
var allStrings = string1 + ',' + string2 + ',' + string3 + ','+ string4;
var distinctNumbers = new List<string>(allStrings.Split(',').Distinct());
Output :
4
5
7
9
6
1
distinctNumbers = Count = 6
add a comment |
He can you try this out
var string1 = "4,5";
var string2 = "7,9";
var string3 = "4,7,6,1";
var string4 = "1";
var allStrings = string1 + ',' + string2 + ',' + string3 + ','+ string4;
var distinctNumbers = new List<string>(allStrings.Split(',').Distinct());
Output :
4
5
7
9
6
1
distinctNumbers = Count = 6
add a comment |
He can you try this out
var string1 = "4,5";
var string2 = "7,9";
var string3 = "4,7,6,1";
var string4 = "1";
var allStrings = string1 + ',' + string2 + ',' + string3 + ','+ string4;
var distinctNumbers = new List<string>(allStrings.Split(',').Distinct());
Output :
4
5
7
9
6
1
distinctNumbers = Count = 6
He can you try this out
var string1 = "4,5";
var string2 = "7,9";
var string3 = "4,7,6,1";
var string4 = "1";
var allStrings = string1 + ',' + string2 + ',' + string3 + ','+ string4;
var distinctNumbers = new List<string>(allStrings.Split(',').Distinct());
Output :
4
5
7
9
6
1
distinctNumbers = Count = 6
answered Nov 22 '18 at 7:37
Rod lauro RomarateRod lauro Romarate
12
12
add a comment |
add a comment |
This is a longer one than the others, but it might be easier to understand how it works.
List<string> str = new List<string> {"1", "3", "1", "2", "3", "43", "23", "54", "3"," "4 };
List<string> foundstr = new List<string> { };
foreach (string check in str)
{
bool found = false;
//going through every single item in the list and checking if it is found in there
for (int i = 0; i < foundstr.Count; i++)
{
//if found then make found(bool) true so we don't put it in the list
if(check == foundstr[i])
{
found = true;
}
}
//checking if the string has been found and if not then add to list
if(found == false)
{
foundstr.Add(check);
}
}
foreach(string strings in foundstr)
{
Console.WriteLine(strings);
}
Console.ReadLine();
add a comment |
This is a longer one than the others, but it might be easier to understand how it works.
List<string> str = new List<string> {"1", "3", "1", "2", "3", "43", "23", "54", "3"," "4 };
List<string> foundstr = new List<string> { };
foreach (string check in str)
{
bool found = false;
//going through every single item in the list and checking if it is found in there
for (int i = 0; i < foundstr.Count; i++)
{
//if found then make found(bool) true so we don't put it in the list
if(check == foundstr[i])
{
found = true;
}
}
//checking if the string has been found and if not then add to list
if(found == false)
{
foundstr.Add(check);
}
}
foreach(string strings in foundstr)
{
Console.WriteLine(strings);
}
Console.ReadLine();
add a comment |
This is a longer one than the others, but it might be easier to understand how it works.
List<string> str = new List<string> {"1", "3", "1", "2", "3", "43", "23", "54", "3"," "4 };
List<string> foundstr = new List<string> { };
foreach (string check in str)
{
bool found = false;
//going through every single item in the list and checking if it is found in there
for (int i = 0; i < foundstr.Count; i++)
{
//if found then make found(bool) true so we don't put it in the list
if(check == foundstr[i])
{
found = true;
}
}
//checking if the string has been found and if not then add to list
if(found == false)
{
foundstr.Add(check);
}
}
foreach(string strings in foundstr)
{
Console.WriteLine(strings);
}
Console.ReadLine();
This is a longer one than the others, but it might be easier to understand how it works.
List<string> str = new List<string> {"1", "3", "1", "2", "3", "43", "23", "54", "3"," "4 };
List<string> foundstr = new List<string> { };
foreach (string check in str)
{
bool found = false;
//going through every single item in the list and checking if it is found in there
for (int i = 0; i < foundstr.Count; i++)
{
//if found then make found(bool) true so we don't put it in the list
if(check == foundstr[i])
{
found = true;
}
}
//checking if the string has been found and if not then add to list
if(found == false)
{
foundstr.Add(check);
}
}
foreach(string strings in foundstr)
{
Console.WriteLine(strings);
}
Console.ReadLine();
answered Nov 22 '18 at 8:23
Code ChapterCode Chapter
86
86
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425077%2fget-all-unique-values-out-of-strings%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What did you mean by
unique value
?– Saif
Nov 22 '18 at 6:34
2
do some research on
linq
anddistinct
– JohnB
Nov 22 '18 at 6:35
He probably means distinct values.
– Uwe Keim
Nov 22 '18 at 6:35
No I guess OP want value where
occurrence is one
– Prasad Telkikar
Nov 22 '18 at 6:37
OP wants to get a
distinct
list of numbers i believe - ie no duplicates– JohnB
Nov 22 '18 at 6:38