| View previous topic :: View next topic |
| Author |
Message |
Danny Young Newbie

Joined: 16 Aug 2002 Posts: 4 Location: Manchester, England
|
Posted: Sat Aug 17, 2002 10:31 am Post subject: Some string manipulation functions... |
|
|
Hi
Thought I'd give VDS 4.5 a whirl after not touching it for a couple of years, and I've come up with a few string manipulation techniques, including Replace, Reverse, InStrRev (which is @POS() in reverse) and a VDS function parser... Give them a go, you might find them useful one day...
available here
cheers, dan.
p.s. I'm not sure if that parser is in violation of the t&c's, but if it is, just let me know and I'll chuck it out. |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Tue Aug 27, 2002 4:44 pm Post subject: |
|
|
I tried to download that, but it doesn't exists...
Ps. Here is a routine which you can use to Reverse a string:
| Code: |
%%string = hello world
:Reverse-string
%%justavariable = @len(%%string)
repeat
%%string2 = %%string2@substr(%%string,%%justavariable,%%justavariable)
%%justavariable = @pred(%%justavariable)
until @equal(%%justavariable,0)
%%string = %%string2
exit
|
|
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Tue Aug 27, 2002 10:02 pm Post subject: |
|
|
Hey guys!
lasrever gnirts taht htiw tib a dnuora gniyalp pleh t'ndluoc tsuJ
ahhh, I mean:
Just couldn't help playing around a bit with that string reversal
So here's another routine:
| Code: |
%%string = hello world
%%len = @len(%%string)
%%inc = 0
repeat
%%inc = @succ(%%inc)
%%string2 = @strins(%%string2,1,@substr(%%string,%%inc,))
until @equal(%%inc,%%len)
info %%string = %%string2
|
Greetz
daerD .rD  _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Tue Aug 27, 2002 11:33 pm Post subject: |
|
|
Hey, can I play too?
| Code: |
%%s1 = "Hello World"
%s = %%s1
REPEAT
%r = %r@substr(%s,@len(%s))
%s = @strdel(%s, @len(%s))
UNTIL @equal(@len(%s), 0)
INFO %%s1@cr()@cr()%r
|
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Wed Aug 28, 2002 2:16 am Post subject: |
|
|
Hmmmmm..... Danny Young? From England? Name sounds
familiar... Have you been here before? Say maybe several
years ago? Maybe in your mid to late teen years now?
-Garrett |
|
| Back to top |
|
 |
Protected Valued Contributor


Joined: 02 Jan 2001 Posts: 228 Location: Portugal
|
Posted: Wed Aug 28, 2002 2:21 am Post subject: |
|
|
| Danny has been here for a long time, I remember when I first came here, the page was still the old one with the blue layout and his name and ICQ number were in the ICQ numbers page (he was like the second in the list, or at least he was near the top). |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Wed Aug 28, 2002 3:31 am Post subject: |
|
|
Then that's why his name sounds so familiar to me!
-Garrett |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Sun Sep 01, 2002 6:26 pm Post subject: |
|
|
I had nothing to do, so I tried to make that InStrRev to work. It is nothing else than reverseing the two @pos() parameters...
| Code: |
%%InStrRevchr = Hello
%%InStrRevstring = Hello world
gosub InStrRev
info %%InStrRevchr" is the "%%InStrRevpos"th from the right..."
exit
:InStrRev
%%justavariable = @len(%%InStrRevchr)
repeat
%%string1 = %%string1@substr(%%InStrRevchr,%%justavariable,%%justavariable)
%%justavariable = @pred(%%justavariable)
until @equal(%%justavariable,0)
%%justavariable = @len(%%InStrRevstring)
repeat
%%string2 = %%string2@substr(%%InStrRevstring,%%justavariable,%%justavariable)
%%justavariable = @pred(%%justavariable)
until @equal(%%justavariable,0)
%%InStrRevstring = %%string2
%%InStrRevpos = @fadd(@pos(%%string1,%%InStrRevstring),@len(%%string1))
rem If you only need to know the first Characters pos, use this...
rem %%InStrRevpos = @pos(%%string1,%%InStrRevstring)
exit |
|
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Sun Sep 01, 2002 6:37 pm Post subject: |
|
|
I had still nothing to do...
| Code: |
%%String = Hello world
%%Replace = Hello
%%ReplaceWith = Hi
gosub Replace-String
info %%String
exit
:Replace-String
%%String = @strins(@strdel(%%String,@pos(%%Replace,%%String),@pred(@fadd(@pos(%%Replace,%%String),@len(%%Replace)))),@pos(%%Replace,%%String),%%Replacewith)
exit |
Btw. Danny, what do you mean with Function Parser? |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Sun Sep 01, 2002 9:00 pm Post subject: |
|
|
Was that against the terms and conditions, because it is not there anymore...  _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Sun Sep 01, 2002 10:04 pm Post subject: |
|
|
I also found, a long time ago on Google.com, a sample source code for a VDS DLL that would reverse a string when you use an @reverse() function...I'm not sure who wrote it...I can't remember where I got it, but if it is a violation of copyright or anything, just let me know and I'll take it off as soon as I can.
Here is "Test.dpr":
| Code: | library Test;
uses
TestDLL in 'TESTDLL.PAS';
exports
Init, CommandProc, FuncProc, StatProc;
begin
end. |
Here is "TestDLL.pas":
| Code: | unit TestDLL;
(* This example of a Visual DialogScript extension DLL implements a
command and function called REVERSE.
REVERSE ON turns the function on.
REVERSE OFF turns the function off.
When the function is on, @REVERSE() returns the string given as its
argument with all the characters reversed. When the function is off
it returns the string unchanged.
To demonstrate an event, a REVERSE event is triggered if REVERSE is
given with any parameter other than ON or OFF.
*)
interface
(* Note that 16-bit DLLs must use the Pascal calling convention.
32-bit DLLs must use the C calling convention *)
uses
WinTypes, WinProcs, SysUtils;
type
exteventproc = procedure(eventtype: PChar);
{$IFNDEF VER80}
cdecl;
{$ENDIF}
const
max_par = 1; { maximum number of params/args (user-definable) }
buf_size = 256; { parameter buffer size (user-definable) }
var
AHandle: THandle; { application handle }
eventproc: exteventproc;
p, errorcode: Integer;
parambuf: Array[0..buf_size-1] of Char; { use GetMem/FreeMem for large buffers }
{ start user-defined variables }
rstat: Boolean;
{ end user-defined variables }
function Init(Handle: THandle; Addr: exteventproc; KeyString: PChar; var maxpar,bufsize: Integer): PChar; export;
{$IFNDEF VER80}
cdecl;
{$ENDIF}
(*
This function is called when the extension is declared using the EXTERNAL
command.
Handle is the DialogScript application's handle, which is passed in case
it is needed by any of the DLL functions.
Addr is the address of the callback function which is used so that the
extension DLL can notify VDS of events.
KeyString can be anything, including null. It is the contents of the second
parameter to the EXTERNAL command. It could be used, for example, to pass
a serial number code so the DLL can check whether the calling program is
licensed to use it, or a version number so the DLL can check if it is
compatible. The string can be used for anything you like.
Any initialisation of the DLL should be performed during this function.
If everything is OK then the DLL should return a string containing the name
of the command/function which will be used to call the extension. If something
is wrong then a null string should be returned, which will cause VDS to halt
with an error.
*)
function CommandProc(Params: PChar): Integer; export;
{$IFNDEF VER80}
cdecl;
{$ENDIF}
(*
This function is called when the extension command is called. The parameters
on the command line are passed in Params as a series of concatenated null
terminated strings, and can be read using the NextParam function.
The return value should be:
0 - everything OK: OK indicator left true
-1 - non-fatal error: OK indicator set false;
>0 - a standard VDS error code (errno is set to this)
*)
function FuncProc(Args: PChar): PChar; export;
{$IFNDEF VER80}
cdecl;
{$ENDIF}
(*
This function is called when the extension function is called. The arguments
are passed in Args as a series of concatenated null terminated strings, and
can be read using the NextParam function.
The return value is the string value that is substituted for the function.
The function StatProc is called immediately after FuncProc to get the value
of OK / errorcode.
*)
function StatProc: Integer; export;
{$IFNDEF VER80}
cdecl;
{$ENDIF}
(*
This function is called by VDS immediately after FuncProc to obtain the
value of OK and errorcode.
*)
implementation
{ begin utility functions (not exported) }
function NextParam: PChar; {get next command parameter}
begin
Result := Addr(parambuf[p]);
while parambuf[p]<>#0 do
begin
inc(p);
end;
inc(p);
end;
{ end utility functions }
{ begin exported functions }
function Init(Handle: THandle; addr: exteventproc; KeyString: PChar; var maxpar,bufsize: Integer): PChar;
begin
AHandle := Handle;
eventproc := addr;
maxpar := max_par;
bufsize := buf_size;
{ start user-defined code }
if StrComp(KeyString,'DEMO') = 0 then {for this example, the second param}
begin {to EXTERNAL should be 'DEMO'}
Result := 'REVERSE'; {return the command/function name }
rstat := true; {initialisation}
end
else
Result := ''; {return null - KeyString not accepted}
{ end user-defined code (remember to set Result) }
end;
function CommandProc(Params: PChar): Integer;
var
cmdtype: Array[0..7] of Char;
begin
errorcode := 0; {initialise errorcode}
for p := 0 to pred(buf_size) do
parambuf[p] := Params[p]; {copy parameter string into buffer}
p := 0; {set pointer for NextParam}
{ start user-defined code }
StrCopy(cmdtype,StrUpper(NextParam));
if StrComp(cmdtype,'ON') = 0 then {command parameter 'ON'}
rstat := true
else if StrComp(cmdtype,'OFF') = 0 then {command parameter 'OFF'}
rstat := false
else
exteventproc(eventproc)('REVERSE'); {example of generating an event}
{ end user-defined code }
Result := errorcode;
end;
function FuncProc(Args: PChar): PChar;
var
arg,
resbuf: Array[0..255] of Char;
p1,p2: Integer;
begin
{ don't zeroise errorcode in case it is set by previous function }
for p := 0 to pred(buf_size) do
parambuf[p] := Args[p]; {copy parameter string into buffer}
p := 0; {set pointer for NextParam}
{ start user-defined code }
StrCopy(arg,NextParam);
if rstat then
begin
p1 := 0;
p2 := StrLen(arg);
if p2 = 0 then
errorcode := 34
else
begin
resbuf[p2] := #0;
repeat
dec(p2);
resbuf[p1] := arg[p2];
inc(p1);
until p2 = 0;
end;
end
else
StrCopy(resbuf,arg);
{ end user-defined code }
Result := resbuf;
end;
function StatProc: Integer;
{ this function requires no modification }
begin
Result := errorcode;
end;
end. |
If it is a violation of copyright or anything I'll take it off as soon as possible.[/code] _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Sun Sep 01, 2002 10:10 pm Post subject: |
|
|
Here's a demo script for the code...
| Code: | title Reverse Demo
external reverse.dll,DEMO
info @reverse(Hello world)
exit |
_________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Sat Sep 07, 2002 1:43 pm Post subject: |
|
|
If you search for MSN Messenger Add-ons you'll find a lot of programs that can make your Friendlyname like "F r I e N d L y N a M e".
With this code it is easy to do that on your own...
| Code: |
%%String = Friendlyname
rem Makes the text likes "FrIeNdLyNaMe"
gosub StRaNgEtExT
info %%String
rem Makes the text likes "F r I e N d L y N a M e"
gosub Placespaces
info %%String
exit
:StRaNgEtExT
%%string = @lower(%%string)
%z = 1
repeat
%%string = @strins(@strdel(%%string,%z,%z),%z,@upper(@substr(%%string,%z,%z)))
%z = @fadd(%z,2)
until @greater(%z,@len(%%string))
exit
:Placespaces
%z = 0
repeat
%%string = @strins(%%string,%z,@chr(32))
%z = @fadd(%z,2)
until @greater(%z,@len(%%string))
exit
|
|
|
| Back to top |
|
 |
Danny Young Newbie

Joined: 16 Aug 2002 Posts: 4 Location: Manchester, England
|
Posted: Sat Sep 07, 2002 1:59 pm Post subject: |
|
|
Hello Garrett,
Long time no see.
| Code: |
rem BOF--- (note: SADE should really make a @REVERSE() function. (it'd speed this code up somewhat)
rem and add a "Start From" argument to @POS() - you don't
rem always want to start from pos 1.
Title "VDS/VDS Parser"
info "VB Result: "@fadd(@fsub(@fmul(@fdiv(10,@fdiv(10,2)),10),5),85)
%%Parse = "@fadd(@fsub(@fmul(@fdiv(10,@fdiv(10,2)),10),5),85)"
GoSub ParseFunctions
info "Parser Result: "%%Parse
Exit
:ParseFunctions
rem ################################################################
rem # ParseFunctions - Will traverse nested-functions and call
rem # ParseFunction accordingly.
rem # Usage:
rem # 1. Put functions in %%Parse
rem # 2. GoSub ParseFunctions
rem #
rem # Result can now be found in %%Parse
rem #
rem # This procedure uses procedures "ParseFunction", "Reverse"
rem # and "InStrRev".
rem #
rem # Internal Variables Used:
rem # 1. %%Parse_Temp
rem # 2. %%Parse_Pos
rem # 3. %%Parse_Function
rem #
rem # I don't know of a use for this really. I can only imagine
rem # it being of use to people who wants to work on some code
rem # remotely... by means of a remote-control software (like NetBus)
rem #
rem # Danny Young
rem # dan@mydan.com
rem ################################################################
%%InStrRev_Check = %%Parse
%%InStrRev_Match = "@"
GoSub InStrRev
While @Not(@Zero(%%InStrRev_Check%%))
%%Parse_Temp = @SubStr(%%Parse,%%InStrRev_Check,@Len(%%Parse))
%%Parse_Pos = @Pos(")",%%Parse_Temp)
%%Parse_Function = @SubStr(%%Parse_Temp,2,@Pred(%%Parse_Pos))
GoSub ParseFunction
If @Equal(%%InStrRev_Check,1)
%%Parse = %%Parse_Function@SubStr(%%Parse_Temp,@Succ(%%Parse_Pos),@Len(%%Parse_Temp))
Else
%%Parse = @SubStr(%%Parse,1,@Pred(%%InStrRev_Check))%%Parse_Function@SubStr(%%Parse_Temp,@Succ(%%Parse_Pos),@Len(%%Parse_Temp))
End
If @Not(@Equal(%%InStrRev_Check,1))
%%InStrRev_Check = %%Parse
%%InStrRev_Match = "@"
GoSub InStrRev
Else
%%InStrRev_Check = 0
End
WEnd
Exit
:ParseFunction
rem ################################################################
rem # ParseFunction - Return result from given arguments and action
rem # Usage:
rem # 1. Put action and arguments into %%Parse_Function
rem # [following format: action(argument1,argument2]
rem # e.g. fdiv(10,2
rem # 2. GoSub ParseFunction
rem #
rem # Result can now be found in %%Parse_Function
rem #
rem # Internal Variables Used:
rem # 1. %%Parse_FunctionName (Stores the action to perform)
rem # (any number of: %%Parse_ArgumentX, depending on
rem # each function)
rem # -- And that is why you can't have just the one parse command
rem # -- at the top of the function. Because you don't know how
rem # -- which function you're going to be using.
rem #
rem # Danny Young
rem # dan@mydan.com
rem ################################################################
Option Fieldsep, "("
Parse "%%Parse_FunctionName;%%Parse_FunctionArguments", %%Parse_Function
Option Fieldsep, ","
%%Parse_FunctionName = @Lower(%%Parse_FunctionName)
If @Equal(%%Parse_FunctionName,"fadd")
Parse "%%Parse_Argument1;%%Parse_Argument2", %%Parse_FunctionArguments
%%Parse_Function = @FAdd(%%Parse_Argument1,%%Parse_Argument2)
ElsIf @Equal(%%Parse_FunctionName,"fsub")
Parse "%%Parse_Argument1;%%Parse_Argument2", %%Parse_FunctionArguments
%%Parse_Function = @FSub(%%Parse_Argument1,%%Parse_Argument2)
ElsIf @Equal(%%Parse_FunctionName,"fmul")
Parse "%%Parse_Argument1;%%Parse_Argument2", %%Parse_FunctionArguments
%%Parse_Function = @FMul(%%Parse_Argument1,%%Parse_Argument2)
ElsIf @Equal(%%Parse_FunctionName,"fdiv")
Parse "%%Parse_Argument1;%%Parse_Argument2", %%Parse_FunctionArguments
%%Parse_Function = @FDiv(%%Parse_Argument1,%%Parse_Argument2)
rem # the following two just show ways to parse 1 or 3 arguments...
rem ElsIf @Equal(%%Parse_FunctionName,"succ")
rem %%Parse_Function = @Succ(%%Parse_FunctionArguments)
rem ElsIf @Equal(%%Parse_FunctionName,"fdiv")
rem Parse "%%Parse_Argument1;%%Parse_Argument2;%%Parse_Argument3", %%Parse_FunctionArguments
rem %%Parse_Function = @SubStr(%%Parse_Argument1, %%Parse_Argument2, %%Parse_Argument3)
End
Exit
:InStrRev
rem ################################################################
rem # InStrRev - @Pos() Reversed.
rem # Usage:
rem # 1. Put string to be searched through into %%InStrRev_Check
rem # 2. Put string to be found into %%InStrRev_Match
rem # 2. GoSub InStrRev
rem #
rem # Position of %%InStrRev_Match in %%InStrRev_Check from the end
rem # can now be found in %%InStrRev_Check
rem #
rem # Internal Variables Used:
rem # 1. %%InStrRev_Pos (Stores value from @Pos() used in this)
rem #
rem # Danny Young
rem # dan@mydan.com
rem ################################################################
%%Reverse_String = %%InStrRev_Check
GoSub Reverse
%%InStrRev_Check = %%Reverse_String
%%Reverse_String = %%InStrRev_Match
GoSub Reverse
%%InStrRev_Match = %%Reverse_String
%%InStrRev_Pos = @Pos(%%InStrRev_Match,%%InStrRev_Check)
If @Zero(%%InStrRev_Pos)
%%InStrRev_Check = 0
Else
%%InStrRev_Check = @Sum(@FSub(@FSub(@Len(%%InStrRev_Check),%%InStrRev_Pos),@Len(%%InStrRev_Match)),2)
End
Exit
:Reverse
rem ################################################################
rem # String Reverse
rem # Usage:
rem # 1. Put string to be reversed into %%Reverse_String
rem # 2. GoSub Reverse
rem #
rem # Reversed string is now available using %%Reverse_String
rem #
rem # Internal Variables Used:
rem # 1. %%Reverse_nLength (Counter)
rem # 2. %%Reverse_sOut (Used in REPEAT to form reversed string)
rem #
rem # Danny Young
rem # dan@mydan.com
rem ################################################################
%%Reverse_nLength = @Len(%%Reverse_String)
%%Reverse_sOut = ""
Repeat
%%Reverse_sOut = %%Reverse_sOut@SubStr(%%Reverse_String,%%Reverse_nLength,%%Reverse_nLength)
%%Reverse_nLength = @Pred(%%Reverse_nLength)
Until @Equal(%%Reverse_nLength, 0)
%%Reverse_String = %%Reverse_sOut
Exit
rem # This Replace function isn't used, but you may find it handy sometime...
:Replace
rem ################################################################
rem # Replace
rem # Usage:
rem # 1. Put string to be checked into %%Replace_Check
rem # 2. Put string to be found into %%Replace_Match
rem # 3. Put string to replace with into %%Replace_With
rem # 2. GoSub Replace
rem #
rem # Replaced string is now available using %%Replace_Check
rem #
rem # Internal Variables Used:
rem # 1. %%Replace_Pos (Position of %%Replace_Match within string)
rem #
rem # Danny Young
rem # dan@mydan.com
rem ################################################################
%%Replace_Pos = @Pos(%%Replace_Match,%%Replace_Check)
While @Not(@Zero(%%Replace_Pos))
If @Equal(%%Replace_Pos,1)
%%Replace_Check = %%Replace_With@SubStr(%%Replace_Check,@Sum(%%Replace_Pos,@Len(%%Replace_Match)),@Sum(@FSub(@Len(%%Replace_Check),%%Replace_Pos),1))
Else
%%Replace_Check = @SubStr(%%Replace_Check,1,@Pred(%%Replace_Pos))%%Replace_With@SubStr(%%Replace_Check,@Sum(%%Replace_Pos,@Len(%%Replace_Match)),@Len(%%Replace_Check))
End
%%Replace_Pos = @Pos(%%Replace_Match,%%Replace_Check)
WEnd
Exit
rem ---EOF
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|