Your question, your audience. Choose who sees your identityâ€”and your questionâ€”with question security.

I need to do a range-validation.

The ranges are composed this way :

Beginnig with a number (max 999) and eventuelally 1 char (max 1 char)=> for example 2a.

They come always in in pairs but the beginpoint can be used as an endpoint too in the same range..

A range is thus expressed this way : from [1 to 3 ] or [1a-1a], or [1a-10]

Verification is needed as described hereby :

- No use of the same is permitted : so the same range must be excluded.

- No overlap is permitted : so the range [2 to 10] is not allowed if range [1-3] already exists

- If range [1 to 3] is given and a second range [4 to 10] exists, another range can still be created between them => 3a - 3f.

- In the same way, if the range is given [1 to 3], 2a is already taken because 2a < 3.

- In the same way, the range [4-10] does not comprise the range [10a-16] : 10a > 10

Is it possible to construct this in an algorithm to verify these ranges?

How do I best proceed for the creation? Any examples?

I already use this code :

class Range<T>

{

public readonly T Start;

public readonly T End;

public Range(T start, T end)

{

this.Start = start;

this.End = end;

}

}

static class Range

{

public static bool Overlap<T>(Range<T> left, Range<T> right)

where T : IComparable<T>

{

if (left.Start.CompareTo(right.Start) == 0)

{

return true;

}

else if (left.Start.CompareTo(right.Start) > 0)

{

return left.Start.CompareTo(right.End) <= 0;

}

else

{

return right.Start.CompareTo(left.End) <= 0;

}

}

}

Tanks for any help.

The ranges are composed this way :

Beginnig with a number (max 999) and eventuelally 1 char (max 1 char)=> for example 2a.

They come always in in pairs but the beginpoint can be used as an endpoint too in the same range..

A range is thus expressed this way : from [1 to 3 ] or [1a-1a], or [1a-10]

Verification is needed as described hereby :

- No use of the same is permitted : so the same range must be excluded.

- No overlap is permitted : so the range [2 to 10] is not allowed if range [1-3] already exists

- If range [1 to 3] is given and a second range [4 to 10] exists, another range can still be created between them => 3a - 3f.

- In the same way, if the range is given [1 to 3], 2a is already taken because 2a < 3.

- In the same way, the range [4-10] does not comprise the range [10a-16] : 10a > 10

Is it possible to construct this in an algorithm to verify these ranges?

How do I best proceed for the creation? Any examples?

I already use this code :

class Range<T>

{

public readonly T Start;

public readonly T End;

public Range(T start, T end)

{

this.Start = start;

this.End = end;

}

}

static class Range

{

public static bool Overlap<T>(Range<T> left, Range<T> right)

where T : IComparable<T>

{

if (left.Start.CompareTo(righ

{

return true;

}

else if (left.Start.CompareTo(righ

{

return left.Start.CompareTo(right

}

else

{

return right.Start.CompareTo(left

}

}

}

Tanks for any help.

if those two conditions are true then the ranges overlap. You don't need to check anything else

But, I need string because a range can be defined like [3a-6] or even [3a-3d].

a=.01

b=.02

c=.03

....

z=.26

so [3a-6j] would be 3.01 - 6.10

If I have to compare [13a] with [20] I have to add a char befor the [20] too. The comparison works from left to right. This way, 1 will be smaller van 2 because it is now verified at the same level.

I still have to check it out more profoundly, but the first test seems to be positif.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

the string "1234a" is less than the string "2"

i think it's safer to turn alphanumeric to pure numeric. and very easy to do so too...

you could use the ascii value of the character divided by 1000 as your decimal.

a = .097

b = .098

...

z= .122

that makes your conversion very easy and always a safe comparison