Page 1 of 1

[DLL] Search and replace Strings via RegExp

Posted: Sat Oct 21, 2006 12:12 pm
by FloHimself
This is a tiny DLL I hacked for Kiffi on the german forums. Initially I didn't want to post it, because it's really very simple. But maybe it's also useful for someone else. Because I am on Linux, I haven't tested this extensively. This software may contain bugs!

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.
This package includes a DLL, the source and the example: download here

Posted: Sat Oct 21, 2006 2:46 pm
by benny
Thanx for sharing, Flo :!:

Posted: Sun Oct 22, 2006 4:53 am
by fsw
Thanks.

[offtopic]
BTW: You are working with D ?
How do you like it ?
[/offtopic]

Posted: Sun Oct 22, 2006 9:25 am
by FloHimself
Hey we're at the PB forums here! :D
I'll just say: Try D! Just try it and forget about C/C++!

Posted: Mon Mar 05, 2007 4:31 pm
by Hroudtwolf
Hi,

Could you fix the download link, please ?

Thanks :)

Posted: Mon Mar 05, 2007 5:02 pm
by FloHimself
Fixed.

Posted: Mon Mar 05, 2007 8:51 pm
by Hroudtwolf
Thank you very much.