11,575,925 members (59,576 online)
Rate this:
See more:
hi
i want to get specific sub string from the string .. Explanation
if i have
string hex= " 7E 00 0F 10 01 00 13 A2 00 40 81 AB C4 FF FE 00 00 01 0B " ;

01 at end of string only from the string But ! i dont wanna make it with the normal substring function because in my case 01 may variate it can be 01 c5 or anything .. number of bites is not constant
in other way we can express it like
" 7E 00 0F 10 01 00 13 A2 00 40 81 AB C4 FF FE 00 00 (N) 0B "
While N is variable length ..but other packet parts is const length .
btw This is apacket and 01 or N is RF Data
Thanks
Posted 8-Jan-13 23:48pm
Edited 8-Jan-13 23:58pm
v2

Rate this:

## Solution 1

Use a Regex:
```string hex1 = " 7E 00 0F 10 01 00 13 A2 00 40 81 AB C4 FF FE 00 00 01 0B ";
string hex2 = " 7E 00 0F 10 01 00 13 A2 00 40 81 AB C4 FF FE 00 00 01 FF FE 66 0B ";
Regex reg = new Regex(@"(?<=7E 00 0F 10 01 00 13 A2 00 40 81 AB C4 FF FE 00 00 )(.. )*(?=0B )");
Match m = reg.Match(hex1);
if (m.Success)
{
Console.WriteLine(m.Value);
}
m = reg.Match(hex2);
if (m.Success)
{
Console.WriteLine(m.Value);
}```
Will produce:
```01
01 FF FE 66 ```
promarkoo at 9-Jan-13 7:21am

data inside the string is not constant ... it is generated each calculation process . i was thinking if i can make like the first part of regex variable
like x=substring(0,20);
OriginalGriff at 9-Jan-13 7:36am

You can. Assuming your data starts with a 7E, you could discard the next 6 data pairs like this:
(?<=7E (.. ){6})(.. )*(?=0B )
And it would start capture with the A2 in your example.