From 005b40a48fb4b38d12ab2cc5774881ca63fd7a2e Mon Sep 17 00:00:00 2001 From: Bukz Date: Thu, 28 Apr 2011 02:14:10 +0000 Subject: [PATCH] strins - Returns string B inserted into string A at position X. git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6384 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- config/docs.cfg | 7 +++++++ config/scripts.cfg | 13 +++++++++++++ docs/reference.xml | 30 +++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/config/docs.cfg b/config/docs.cfg index 69344bbd..110d9d2e 100644 --- a/config/docs.cfg +++ b/config/docs.cfg @@ -152,6 +152,13 @@ docexample [if (strstr "Hello world!" Hello) [echo found Hello in Hello world!] docident [strlen] [Returns the length (in characters, including whitespace) of string S.]; docargument [S] [The string to check.] [] [0]; docexample [echo (strlen "Hello world!")] [output: 12]; +docident [strins] [Returns string B inserted into string A at position X.]; +docargument [A] [the original string] [] [0]; +docargument [B] [the string to insert into the original] [] [0]; +docargument [P] [the position at which to insert string B into string A] [] [0]; +docexample [echo (strins "Hello world" " cruel" 5)] [Output: Hello cruel world]; +docexample [tmp = "Hello world"; echo (strins $tmp " cruel" (strlen $tmp))] [Output: -1]; +docremark []; docident [substr] [Copies a substring out of the original]; docargument [S] [The original string.] [] [0]; docargument [A] [The starting position.] [] [0]; diff --git a/config/scripts.cfg b/config/scripts.cfg index aaccfa87..b1466059 100644 --- a/config/scripts.cfg +++ b/config/scripts.cfg @@ -419,6 +419,19 @@ storesets = [ ] ] +// strins - Inserts a string into another string, at position x. +strins = [ + if (> $numargs 2) [ + if (&& (> $arg3 -1) (< $arg3 (strlen $arg1))) [ + tmp_output = "" + loop sil (strlen $arg1) [ + if (= $sil $arg3) [ tmp_output = (concatword $tmp_output $arg2 (substr $arg1 $sil 1)) ] [ tmp_output = (concatword $tmp_output (substr $arg1 $sil 1)) ] + ] + result $tmp_output + ] [ result -1 ] + ] +] + // cleanshot - Take a "clean" screenshot with no HUD items. cs_sets = "clockdisplay crosshairsize hidecompass hideconsole hidectfhud hidedamageindicator hidehudequipment hidehudmsgs hideradar hidespecthud hideteam hidevote hudgun spechudgun showstats" cs_newsets = "0 0 1 1 1 1 1 1 1 1 1 1 0 0 0" diff --git a/docs/reference.xml b/docs/reference.xml index a5ae199c..f3140e57 100644 --- a/docs/reference.xml +++ b/docs/reference.xml @@ -429,7 +429,35 @@ - + + + Returns string B inserted into string A at position X. + + + + Output: Hello cruel world + + + + Output: -1 + + + + + + + + + The third argument must be at least greater than -1, and 1 less than the length "(in characters)" of string A, otherwise use concat or concatword. + + + + + + + + + Returns the position of a substring into another