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

PHP 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 08: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:
PHP 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:
PHP 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, 08: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 08: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 06:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.