12,630,455 members (30,814 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 9-Jan-13 0:48am
Updated 9-Jan-13 0:58am
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 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 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.

Top Experts
Last 24hrsThis month
 OriginalGriff 430 ppolymorphe 200 Peter Leow 180 KarstenK 100 F-ES Sitecore 100
 OriginalGriff 1,754 ppolymorphe 1,192 Peter Leow 739 John Simmons / outlaw programmer 665 CPallini 561