Regex problem

Ace Master

Centurion
Joined
Aug 28, 2003
Messages
140
Hi to all.

I'am new with regex option and I know to make some triks but with the problem I have I can't make it working as I want to.

Ex:

I have one serial communication for input and output. With input I don't have any problems, but everything I take out I want to put them in some check box's like this:

Received string :

Di,30,11,22,33,44,1,12356
MT>

I want to put all that in this order:

var1= i
var2=30
var3=11
var4=22
var5=33
var6=44
var7=12356

and....because always is some kind of problem, my received string cand be like that

Di,30,,,,,1,12356
MT>

..and I want the same variables but where is no value, my textbox to be empty

var1= i
var2=30
var3=""
var4=""
var5=""
var6=""
var7=12356

it is possible to make such regex ?

thanks in advance.
 
uhm i dont understand your problem but why dont you just split the string - after cutting the "D" and "MT>" away - at every ','

String[] parts = Data.Split(new Char {','});

Data is a String with your incoming data

Then you can do

Code:
for (int i = 0; i < Data.Length; i++)
{
    TextBox1.Text = String.Format("var{0}={1}", i.ToString, ((Data[i] != null) &&(Data[i] != "")) ? Data[i] : "\"\"" );
}



HINT:
if you dont know that construction of (condition) ? true : false
i explain it here in short

int x = 5;
String text = (x ==5) ? "Yes, X is 5" : "No, S is not 5";

so this is like an if condition, but more like a "inline" if (C++ Coder might understand this in that way)
so the thing after the ? and before : is the output if the condition true if not then the output is the thing after the :
thats all
 
btw ...how to split a string like 123456 to:

var(1) = 1
var(2) = 2
var(3) = 3
etc...


I tried split(oldvar,"") ..and not working

thanks.
 
Back
Top