DHCP expression functions (index and substitution)

Glenn Satchell glenn.satchell at uniq.com.au
Tue Jul 27 05:20:20 UTC 2010


Hi Chris

Check out the dhcp-eval man page. Some examples below:

On 07/27/10 11:23, Dorsey, Chris wrote:
> Is there a way to use the DHCP expression syntax to:
>
> 1) return the (n’th) character in a string.

	substring (data-expr, offset, length)

	foo = substring ( string, n, 1);

> 2) perform substring substitution within a given string.

This requires a bit of disassembly, then concat, eg if the substring to 
be replaced is positions m to n:

	pre = substring ( string, 1, m-1 );
	post = substring ( string, n+1, 1000000 );
	result = concat ( pre, "abcdef", post );

The 1000000 in substring returns the remaining chars up to the end of 
the string (unless it is more than 1 million chars long). This can be 
combined into one statement:

	result = concat (
		substring ( string, 1, m-1 ),
		"abcdef",
		substring ( string, n+1, 1000000 )
	);

There are definitely other ways to do it.

> I’m thinking there has to be a way to do this, even though I don’t see
> ‘index()’ or ‘substitution()’ functions.
>
> tia,
> Chris

-- 
regards,
-glenn



More information about the dhcp-users mailing list