Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   replacetext() and striptext() (https://forums.graalonline.com/forums/showthread.php?t=79538)

Tigairius 04-26-2008 08:51 AM

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"");



cbk1994 04-26-2008 06:31 PM

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.

zokemon 04-29-2008 02:46 AM

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"));



Tigairius 04-29-2008 03:39 AM

Quote:

Originally Posted by zokemon (Post 1388145)
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.

Tigairius 12-06-2012 08:36 AM

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.


All times are GMT +2. The time now is 03:31 AM.

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