Hi,
I want to find some 2 consecutive values on a table. Sample is like below. For example I want to find the index vales of "a" or "b".
Column1
a
b
c
d
e
f
a
b
c
f
a
b
How should be the logic?
I want to add all column's value to a datatable or an array? How should be the code, or loops?
regards.
Loading
Hemant SrivastavaPosted Feb 19, 2014, 5:55 PM
class Program
{
public static void Main()
{
char[] list = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'A', 'B', 'C', 'F', 'A', 'B' };
int temp ,tempNext;
for (int i = 0; i < list.Length-1; i++ )
{
temp = (int)list[i];
tempNext = (int)list[i+1];
if (temp + 1 == tempNext)
{
Console.WriteLine("Pair ["+list[i] + ","+ list[i+1] + "] is at index position [" + i +"," + (i+1) + "] respectively "); ;
}
}
Console.ReadLine();
}
}
It will give output you as:
Pair [A,B] is at index position [0,1] respectively
Pair [B,C] is at index position [1,2] respectively
Pair [C,D] is at index position [2,3] respectively
Pair [D,E] is at index position [3,4] respectively
Pair [E,F] is at index position [4,5] respectively
Pair [A,B] is at index position [6,7] respectively
Pair [B,C] is at index position [7,8] respectively
Pair [A,B] is at index position [10,11] respectively
yokzuPosted Feb 19, 2014, 5:25 PM
Yes, index value could be added. Lets assuem there "index" and "column1" columns. I tried somethings, but its'not works.
Ans yes if there are other consecutive values, we should determinde them too, like below.(eg, "cd" and "ab")
Column1
a
b
c
d
e
f
a
b
c
f
a
b
c
d
Hemant SrivastavaPosted Feb 19, 2014, 3:48 PM