DHCP expression functions (index and substitution)

Dorsey, Chris dorsey2 at llnl.gov
Tue Jul 27 17:20:48 UTC 2010


Thanks Glenn,
I was started thinking along the lines of your pre/post example for string substitution. but I botched asking the first question.  What I _meant_ was how to find the index of a given string within a larger string.   For example, how would I perform string substitution on "some:str" or "some:str:here" to change the colon (':') to a dash ('-')?  Keep in mind that the location of the colon can be arbitrary.  It would be great to be able to handle full Perl-style regular expressions, but in lieu of that, having an 'index' function would at least get me started.  I could then use your method to perform the substitution.  Seems like there should be a way to do this, and if not maybe this would be a feature request.

Thanks again,
Chris


-----Original Message-----

Message: 5
Date: Tue, 27 Jul 2010 15:20:20 +1000
From: Glenn Satchell <glenn.satchell at uniq.com.au>
Subject: Re: DHCP expression functions (index and substitution)
To: Users of ISC DHCP <dhcp-users at lists.isc.org>
Message-ID: <4C4E6C94.30709 at uniq.com.au>
Content-Type: text/plain; charset=windows-1252; format=flowed

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