forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Replace in string

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
laurent_H
Contributor
Contributor


Joined: 30 Jun 2001
Posts: 60

PostPosted: Fri Aug 02, 2002 10:18 am    Post subject: Replace in string Reply with quote

Hi,

I don't how can I replace in a string
I have a file that countains text

I want to replace [NAME] by "World" for example

text.txt
***********************
HEllo [NAME]
welcome to vds
***********************


script
**************************
list create,1
list loadfile,1,"text.txt"
rem remplacement
%m = @match(1,[NAME])
%%string = @item(1,%m)

info %%string

_________________
Thanks
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Fri Aug 02, 2002 12:42 pm    Post subject: Reply with quote

You might try this:

Code:

list create,1
  list add,1,***********************
  list add,1,HEllo [NAME]
  list add,1,welcome to vds
  list add,1,***********************

  list SEEK,1,0
  %m = @match(1,[NAME])
  %%item = @item(1,%m)

  %%orgstring = "[NAME]"
  %%repstring = World
  %x = 0

  repeat
    if @match(1,%%orgstring)
      %%item = @item(1)
      repeat
        if @greater(@pos(%%orgstring,%%item), 0)
          %%pos = @pos(%%orgstring,%%item)
          %%item = @strdel(%%item,%%pos,@sum(%%pos,@pred(@len(%%orgstring))))
          %%dummy = "#####"
          %%item = @strins(%%item,%%pos,%%dummy)
        end
      until @equal(@pos(%%orgstring,%%item), 0)
      repeat
        if @greater(@pos(%%dummy,%%item), 0)
          %%pos = @pos(%%dummy,%%item)
          %%item = @strdel(%%item,%%pos,@sum(%%pos,@pred(@len(%%dummy))))
          %%item = @strins(%%item,%%pos,%%repstring)
        end
      until @equal(@pos(%%dummy,%%item), 0)
      list DELETE,1
      list INSERT,1, %%item
    end
    %x = @succ(%x)
  until @equal(%x, @count(1))


list seek,1,0
repeat
  %%show = %%show@cr()@next(1)
until @not(@ok())
info %%show


Greetz
Dr. Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing


Last edited by Dr. Dread on Fri Aug 02, 2002 12:56 pm; edited 2 times in total
Back to top
View user's profile Send private message
laurent_H
Contributor
Contributor


Joined: 30 Jun 2001
Posts: 60

PostPosted: Fri Aug 02, 2002 12:44 pm    Post subject: Reply with quote

Waouh there is no simplier solution ?
_________________
Thanks
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Fri Aug 02, 2002 1:00 pm    Post subject: Reply with quote

You could use a DLL to perform search and replace. VDSXFN.DLL has this feature and so does
VDSSTR.DLL (included in Tommy's vdsdll3, I think).

Greetz
Dr. Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing


Last edited by Dr. Dread on Fri Aug 02, 2002 1:18 pm; edited 1 time in total
Back to top
View user's profile Send private message
laurent_H
Contributor
Contributor


Joined: 30 Jun 2001
Posts: 60

PostPosted: Fri Aug 02, 2002 1:01 pm    Post subject: Reply with quote

is it free dll ?
_________________
Thanks
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Fri Aug 02, 2002 1:15 pm    Post subject: Reply with quote

VDSXFN is freeware. VDSSTR can be found in both a free and a shareware version, I think.

Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Fri Aug 02, 2002 6:09 pm    Post subject: Reply with quote

Code:
List Create,1
List Loadfile,1,"text.txt"
%N = [NAME]
%S = @len(%N)
%R = [REPLACEMENT TEXT]
%M = @match(1,%N)
If %M
%A = @Pos(%N,@item(1))
%B = @substr(@item(1),1,@fsub(%A,1))
%C = @substr(@item(1),@sum(%A,@sum(%S,1)),@len(@item(1)))
List Put,1,%B%R%C
End


Short and simple, but only can replace one instance of the name per
line. Put it in a repeat and you can go down the text file replacing
the name on any other lines, as long as there's only one instance of
the name in a single line.

-Garrett
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Fri Aug 02, 2002 6:25 pm    Post subject: Reply with quote

You can do it a bit easier like this. You can see it's not all that big of a routine with the REM's left out in the [Title] replacer.
Code:
 
Title New Dialog
  DIALOG CREATE,New Dialog,-1,0,240,186
REM *** Modified by Dialog Designer on 8/2/2002 - 13:57 ***
  DIALOG ADD,LIST,LIST1,2,32,180,144
  DIALOG ADD,BUTTON,Replace,154,88,64,24,Replace
  DIALOG SHOW
  LIST LOADTEXT,LIST1
"HELLO [NAME]
"Welcome to [Title]
:Evloop
  wait event
  goto @event()
:ReplaceBUTTON
  REM Length of [Name]
  %%NameLen = 6
  repeat
    REM Position of [Name] in @TEXT()
    %%NamePos = @POS([NAME],@TEXT(List1))
    REM Delete [Name] out of @TEXT()
    %%Text = @STRDEL(@TEXT(List1),%%NamePos,@FADD(%%NamePos,%%NameLen))
    REM Insert World
    %%Text = @STRINS(%%Text,%%NamePos,World)
    REM Replace text in List1
    LIST ASSIGN,LIST1,%%Text
    wait 0.1
  until @NOT(@GREATER(%%NamePos,0))
  %%TitleLen = 7
  repeat
    %%TitlePos = @POS([Title],@TEXT(List1))
    %%Text = @STRDEL(@TEXT(List1),%%TitlePos,@FADD(%%TitlePos,%%TitleLen))
    %%Text = @STRINS(%%Text,%%TitlePos,VDS)
    LIST ASSIGN,List1,%%Text
  until @NOT(@GREATER(%%TitlePos,0))
  goto evloop
:Close
  exit

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Fri Aug 02, 2002 6:27 pm    Post subject: Reply with quote

Oops, took too long to post.
_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
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

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group