13,399,624 members (46,509 online)
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

## 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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 240 phil.o 140 RickZeeland 95 Pete O'Hanlon 90 KarstenK 70
 OriginalGriff 4,904 Maciej Los 2,640 Richard MacCutchan 1,773 CPallini 1,600 Dave Kreskowiak 1,015

Advertise | Privacy |
Web02 | 2.8.180218.2 | Last Updated 9 Jan 2013