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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
mj_cole
Wanderer


Joined: 19 Apr 2001
Posts: 59
Location: USA

PostPosted: Fri Aug 08, 2003 10:05 pm   

reversing a string or searching from the back
 
Is there a simple function to search for a character from the back of a string, like "%pos" but the other way around, or else is there a way to invert a string, so that %pos would effectively be working from the back.

Basically I am writing a script to word wrap descriptions that are input as a long string, into seperate lines no more than 80 characters long.

My method would have been to use the %left function to get 80 characters, then search back for a " ", then split the long string at that point.

Any elegant solutions available?

Regards
Marts
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Aug 09, 2003 1:32 am   
 
You probably want to go another route that works with the lengths of each word instead of the positions of whitespace:

Line.original = your long string
Line.new = "" //will contain wrapped version of original
line.wraplength = 80
line.current = "" //will contain one line's worth of text from original
#noop
#forall %replace(@Line.original," ", "|") {#if ((%len(%concat(@Line.current," ",%i)) <= @Line.wraplength) {Line.current = %concat(%trimleft(@Line.current)," ",%i)} {Line.new = %concat(@Line.new,"%cr",@Line.current);Line.current = ""}}

As always, it's untested and not guaranteed to work.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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