user599807
user599807

Reputation:

Compare a string row

Let´s say that I have a string that looks like this:

string WidthStr= "0086;0086;0086;0086;0086;0086;0086;0086;0085;";

And then i´m picking up the first number:

FirstRollWidthStr = WidthPadLeft.Substring(0, 4);

The question I have is: Is it possible to compare the data i that i got from the row below (FirstRollWidthStr = WidthPadLeft.Substring(0, 4);) with the rest?

So from FirstRollWidthStr = WidthPadLeft.Substring(0, 4); i got: 0086. And there are more numbers in string WidthStr, and the last number are 0085 so it´s different from 0086 so i want to pick up the numbers who are different from the first number.

Upvotes: 1

Views: 145

Answers (2)

Snowbear
Snowbear

Reputation: 17274

var numbers = WidthStr.Split(';').Select(double.Parse).Distinct().ToArray();

Or if you need only numbers different from the first one then (continuing previous code):

var otherNumbers = numbers.Skip(1).Except(numbers.Take(1));

Upvotes: 4

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174457

Try this:

var numbers = WidthStr.Split(';');
if(numbers.Length > 0)
{
    var differentNumbers = numbers.Skip(1).Where(x => x != numbers[0]);
    // ...
}

Upvotes: 0

Related Questions