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 - Title Case / Sentence case

 
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 11:15 am    Post subject: String processing - Title Case / Sentence case Reply with quote

This routine should convert a string to something that could be named 'Title Case', i.e. each word (as defined by the
delimiter %%delim) starts with an upper case character.

Greetz
Dr. Dread

Code:

  %%string = "   this is a TEST strinG "
  %%delim = " "
  REM Value here 1 to keep existing upper-case chars, 0 to lose caps
  %%keepupper = 0
  REM First everything to lower case, if not instructed to keep existing upper-case chars
  if @equal(%%keepupper,0)
    %%string = @lower(%%string)
  end
  %%len = @len(%%string)
  REM Then cycle through the string, char by char
  REM If previous is delimiter - then to upper case
  %%inc = 0
  repeat
    %%inc = @succ(%%inc)
   %%dummy = @substr(%%string,%%inc)
   if @equal(%%prev,%%delim)@equal(%%prev,@cr())
     %%newstring = %%newstring@upper(%%dummy)
   else
      %%newstring = %%newstring%%dummy
   end
   %%prev = %%dummy
  until @equal(%%inc,%%len)
 
  info @CHR(34)%%newstring@CHR(34)


EDIT: Found a much smoother way of doing it. Entire code rewritten.

EDIT2: Added option to keep existing upper-case characters.

_________________
~~ 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
Dr. Dread
Professional Member
Professional Member


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

PostPosted: Thu Sep 19, 2002 1:54 pm    Post subject: Sentence case Reply with quote

And this routine is for 'Sentence case', i.e. after a point or a carriage return the following word gets an initial character in upper case.
Whitespace chars are ignored.

Greetz
Dr. Dread

Code:

  %%string = " this is a TEST strinG. And here this line ends."@cr()@tab()"and ANOTHER LINe.yup."
  rem Value here 1 to keep existing upper-case chars, 0 to lose caps
  %%keepupper = 0
  if @equal(%%keepupper,0)
    %%string = @lower(%%string)
  end
  %%len = @len(%%string)
  rem Then cycle through the string, char by char
  rem If preceded by carriage return/point or carriage return/point+whitespace char - then to upper case
  %%inc = 0
  %%NewSent = 1
  repeat
    %%inc = @succ(%%inc)
    %%dummy = @substr(%%string,%%inc)
   if @equal(%%dummy,".")@equal(%%dummy,@cr())
     %%NewSent = 1
   end 
    if @equal(%%NewSent,1)
     if @equal(%%dummy,.)@equal(%%dummy,@CHR(9))@equal(%%dummy,@CHR(10))@equal(%%dummy,@CHR(11))@equal(%%dummy,@CHR(12))@equal(%%dummy,@CHR(13))@equal(%%dummy,@CHR(32))
        %%newstring = %%newstring%%dummy
     else
       %%newstring = %%newstring@upper(%%dummy)
      %%NewSent = 0
     end
    else
      %%newstring = %%newstring%%dummy
    end
  until @equal(%%inc,%%len)

  info @chr(34)%%newstring@chr(34)

_________________
~~ 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