I have a simple application that has richTextBox and button.
User enters numbers(integers) into richTextBox (one number per line).
When He click the button I want to generate a sql query.
Basically it works if I pass integers into query like this:
SELECT price from products where ID IN (1, 2, 3, 4)
This is when user inputs 1,2,3,4 as lines in richTextBox.
But I would like pass binary(8) instead of integers.
This is my original line of code:
cmdString += " IN (" + string.Join(", ", richTextBox1.Lines) + ") ";
I have tried to change it with LINQ like this:
cmdString += " IN ("
+ string.Join(", ", richTextBox1.Lines.Select(c =>
{ c = "0x"+Convert.ToString(Convert.ToInt32(c), 16);
return c;
}).ToArray())
+ ") ";
What I would like to get:
For example convert:
1 to 0x0000000000000001
30 to 0x000000000000001E
I hope You get the point.
Update:
I’ve done this:
textBox1.Text = string.Join(", ", richTextBox1.Lines.Select(c =>
{
c = "0x" + "0000000000000000".Substring(0, (16 - Convert.ToString(Convert.ToInt32(c), 16).Length)) + Convert.ToString(Convert.ToInt32(c), 16);
return c;
}).ToArray());
Any ideas how to remove second Convert.ToString(Convert.ToInt32(c)) usage? Or maybe do it in another way?
I’ll do this in foreach loop:
Or you can do it in your linq query but not easy to read as foreach one: