Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...