|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: 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. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: 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.
|
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: 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. Hope that helps. |
|
_________________ Asati di tempari! |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: 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 |
|
|
|
|
|