Divas string
funkcijas, kas jums varētu noderēt. Pārpublicētas no s2layers kopienas
ieraksta "bunches
of string functions". Ja kādu dikti interesē, tur ir vēl dažas.
replace_text(string
text, string find, string replacement) : string
"Search within \$text
and replaces any occurences of \$find with \$replacement."
function replace_text(string text, string find, string replacement) : stringexample:
"Search within \$text and replaces any occurences of \$find with \$replacement." { ####################################################### # from lj:mageboltrat's industrial nippon (id=533012) # ####################################################### var string[] findarray; var int pos = 1; foreach var string findcharacter($find) { $findarray[$pos] = $findcharacter; $pos = $pos + 1; } var int place = 1; var bool found = false; var string completedtext = ""; var string foundtext = ""; foreach var string searchcharacter($text) { if ($searchcharacter == $findarray[$place]) { if ($place == $find->length()) { $foundtext = $replacement; $place = 1; } else { $foundtext = $foundtext + $searchcharacter; $place = $place + 1; } } else { $completedtext = $completedtext + $foundtext + $searchcharacter; $foundtext = ""; $place = 1; } } $completedtext = $completedtext + $foundtext; return $completedtext; }
var string replaced_text = replace_text( $e.text, "http://stat.livejournal.com/img/userinfo.gif", "http://pics.livejournal.com/img/fb-userinfo.gif" );------------------------------------
rehtml(string text) : string
"Unescape html in \$text
by replacing > with > and < with <."
replace_text
function rehtml(string text) : stringexample: if html is entered into the customization wizard it is stored inside the property in its escaped form. this function will unescape it.
"Unescape html in \$text by replacing > with > and < with <." { #################################################################### # by lj:masterslacker using lj:mageboltrat's replace_text function # #################################################################### return replace_text(replace_text($text, "<", "<"), ">", ">"); }