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 


String processing - search&replace (+ case-sensitivity)

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 3 Source Code
View previous topic :: View next topic  
Author Message
Dr. Dread
Professional Member
Professional Member


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

PostPosted: Thu Sep 19, 2002 9:56 pm    Post subject: String processing - search&replace (+ case-sensitivity) Reply with quote

This puppy is sorta based on a search and replace idea from PGWARE for moving the string chunkwise off to a
variable. This one goes a level further:
* allows you to toggle case sensitivity
* handles multiple-character search strings

Greetz
Dr. Dread

Code:

  list create,1
  list add,1,"@POS(<String1>,<String2>)
  list add,1,"This function returns the starting character position
  list add,1,"of the first occurrence of <String1> in <String2>.
  list add,1,"The characters in the string are counted from 1.
  list add,1,"The value 0 is returned if either string is empty or
  list add,1,"<String1> does not occur in <String2>.
  list add,1,"Note that the comparison is not case sensitive.

  rem Search string
  %S = "String"
  rem Replace string
  %R = "value"
  rem Toggle case-sensitivity by setting %%casesense to 0 or 1
  %%casesense = 1

  if @equal(%%casesense,1)
    gosub case-sense
  else
    gosub non-sense
  end

  list add,1,@cr()@cr().. by Dr. Dread
  info @text(1)
  list close,1
  exit

:case-sense
  %%index = 0
  repeat
    %%instring = @item(1,%%index)
    %%newstring = ""
    repeat
      %%pos = @pos(%S,%%instring)
      if @greater(%%pos,0)
        if @equal(@substr(%%instring,%%pos,@pred(@sum(%%pos,@len(%S)))),%S,exact)
          if @equal(%%pos,1)
            %%newstring = %%newstring%R
          else
            %%newstring = %%newstring@substr(%%instring,1,@pred(%%pos))%R
          end
          %%instring = @strdel(%%instring,1,@pred(@sum(%%pos,@len(%S))))
        else
          if @equal(%%pos,1)
            %%newstring = %%newstring@substr(%%instring,%%pos,@pred(@sum(%%pos,@len(%S))))
          else
            %%newstring = %%newstring@substr(%%instring,1,@pred(@sum(%%pos,@len(%S))))
          end
          %%instring = @strdel(%%instring,1,@pred(@sum(%%pos,@len(%S))))
        end
      end
    until @equal(%%pos,0)
    %%newstring = %%newstring%%instring
    list put,1,%%newstring
    %%index = @succ(%%index)
  until @equal(%%index,@count(1))
  exit

:non-sense
  %%index = 0
  repeat
    %%instring = @item(1,%%index)
    %%newstring = ""
    repeat
      %%pos = @pos(%S,%%instring)
      if @greater(%%pos,0)
        if @equal(%%pos,1)
          %%newstring = %%newstring%R
        else
          %%newstring = %%newstring@substr(%%instring,1,@pred(%%pos))%R
        end
        %%instring = @strdel(%%instring,1,@pred(@sum(%%pos,@len(%S))))
      end
    until @equal(%%pos,0)
    %%newstring = %%newstring%%instring
    list put,1,%%newstring
    %%index = @succ(%%index)
  until @equal(%%index,@count(1))
  exit

_________________
~~ 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
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 3 Source Code 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