[DLL] Search and replace Strings via RegExp

Share your advanced PureBasic knowledge/code with the community.
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

[DLL] Search and replace Strings via RegExp

Post 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
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
benny
Enthusiast
Enthusiast
Posts: 465
Joined: Fri Apr 25, 2003 7:44 pm
Location: end of www
Contact:

Post by benny »

Thanx for sharing, Flo :!:
regards,
benny!
-
pe0ple ar3 str4nge!!!
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

Thanks.

[offtopic]
BTW: You are working with D ?
How do you like it ?
[/offtopic]
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

Post 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++!
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Hi,

Could you fix the download link, please ?

Thanks :)
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

Post by FloHimself »

Fixed.
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Thank you very much.
Post Reply