Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Sun Dec 31, 2006 5:53 pm   

Need an alias to break apart long strings
 
Ok I am in need of an alias to break apart a long string at the closest .?! char to 230 characters without going over 230. It also needs to break on a space as a last resort if there is no punctuation.

Anyone think they can help me with my quest to break apart long strings?
I just need a rough working example of doing this I should be able to tidy it up to do exactly what I want from there.
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sun Dec 31, 2006 6:12 pm   
 
I can't remember how to set up %format to cut a string down to a certain length, but that sounds like what you need. If you chop the string down to 230 characters using %format and then find the last bit of punctuation in the string that results, you've got your break point. Then you can delete the part you have (the first whole sentences up to 230 characters) and then do it again with what it remains if the string is very long and you want it breaking into less-than-230-characters chunks.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Mon Jan 01, 2007 3:57 am   
 
Here's a bit of regex that should do the trick for you...

Code:

// Try to match the desired markers int eh truncated string
#IF (%regex(%left (@BreakString, 230), ".+[?.!]", pos) == 0) {
    // 0, i.e. no match means we'll check for spaces
    %regex(%left (@BreakString, 230), ".+[ ]", pos)
}

#VAR NewString {%left(@BreakString, @pos)}


You could probably subsitute @pos for a local variable but I didn't test that. I was gonna explain how it works, then I remembered you were a wizard. Very Happy Hope that helps.
_________________
Asati di tempari!
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Mon Jan 01, 2007 8:21 am   
 
Tech I <3 You!!!!!!!! That is exactly the rough sketch I needed!

Here is a rough working copy of what I have.

Code:
BreakString={@RS.Fields("helpfile").Value}
#CALL %vartype(BreakString,3) //make sure we set this variable to a literal string
#WHILE (%len(@BreakString)>230) { // Loop Through breakstring until it is less then 230 chars.
   #IF (%regex(%left(@BreakString, 230), ".+[?.!]", pos) == 0) {
       // 0, i.e. no match means we'll check for spaces
       %regex(%left(@BreakString, 230), ".+[ ]", pos)
   }
#SAY %left(@BreakString, @pos)
BreakString={%right(@Breakstring,%eval(%int(@pos)+1))} // %eval(%int shoud not needed but I havnt tested it yet damn autotypeing bugs!! :p
}
#SAY @BreakString


All I have left to do is pretty it up with some local variables and in few other things and give it a real name :p
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion 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

© 2009 Zugg Software. Hosted by Wolfpaw.net