Example:
Code: Select all
; A very basic example calling D's sub function (wrapped up in an DLL)
; Florian "FloHimself" Schäfer - October 20, 2006 - florian.schaefer@gmail.com
; Usage: See D's documentation on regexp @ http://www.digitalmars.com/d/phobos/std_regexp.html
If OpenLibrary(0, "pbsub.dll")
initial_str$ = "Strap a [b]rocket[/b] engine [b]on[/b] a chicken."
Debug "initial string: " + initial_str$
*p_new_str.l = CallCFunction(0, "pbsub", @initial_str$, "\[b\](.*)\[\/b\]", "<b>$1</b>", "")
Debug "after sub: " + PeekS(*p_new_str)
*p_new_str = CallCFunction(0, "pbsub", @initial_str$, "\[b\](.*)\[\/b\]", "<b>$1</b>", "g")
Debug "after gsub: " + PeekS(*p_new_str)
EndIf
Output:
Code: Select all
initial string: Strap a [b]rocket[/b] engine [b]on[/b] a chicken.
after sub: Strap a <b>rocket</b> engine [b]on[/b] a chicken.
after gsub: Strap a <b>rocket</b> engine <b>on</b> a chicken.