Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-26-2008, 08:51 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
replacetext() and striptext()

replacetext and striptext

Graal Script Code:
function replacetext(textoldtextnewtext) {
  
temp.oldlen   oldtext.length();
  
temp.textdiff newtext.length() - temp.oldlen;
  
  for (
temp.ptext.positions(oldtext)) {
    
temp.pos temp.temp.textdiff * (temp.index ++);
    
text text.substring(0temp.pos) @ newtext text.substring(temp.pos temp.oldlen);
  }
  
  return 
text;
}

function 
striptext(textoldtext) {
  return 
replacetext(textoldtext"");

__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”

Last edited by Tigairius; 12-06-2012 at 07:50 AM.. Reason: Updated
Reply With Quote
  #2  
Old 04-26-2008, 06:31 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
I've needed something like this many times, and I've built my own.

This will save me a lot of time, thanks so much!

rep++ sometime within the next 24 hours, unless I've given too much rep to you. We shall see.
__________________
Reply With Quote
  #3  
Old 04-29-2008, 02:46 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
You could also create a GuiMLTextCtrl, set the text variable to the string with the \n's then just pull out getlines() which will return the lines as an array.

Another option is to savestring() to a temp file, then loadlines(). Both of these are kind of unnecessary though but should be mentioned regardless.

EDIT:
I don't get why you didn't just do like:
Graal Script Code:
function replacetext(text) {
  return(
text.tokenize("\n"));

__________________
Do it with a DON!
Reply With Quote
  #4  
Old 04-29-2008, 03:39 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by zokemon View Post
You could also create a GuiMLTextCtrl, set the text variable to the string with the \n's then just pull out getlines() which will return the lines as an array.

Another option is to savestring() to a temp file, then loadlines(). Both of these are kind of unnecessary though but should be mentioned regardless.

EDIT:
I don't get why you didn't just do like:
Graal Script Code:
function replacetext(text) {
  return(
text.tokenize("\n"));

Well simply tokenizing it caused quite a few problems.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #5  
Old 12-06-2012, 07:36 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Recently needed replacetext again and didn't like what I had in here. So I updated my original post with a couple of changes. The function runs a little faster than the others on the code gallery at the moment too.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”

Last edited by Tigairius; 12-12-2012 at 07:39 PM..
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:53 PM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.