OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: richardedwards on 02 Jul 2006, 10:59:59

Title: string editing question
Post by: richardedwards on 02 Jul 2006, 10:59:59
I have a "stupid question" about string editing I hope someone can solve for me. I used to know how to perform this function but have forgotten!!! :(

anyway I need to manipulate strings, for example I need to know how to make  the following happen ;

"I am a stupid string" - "stupid" = "I am a string"

its a simple one liner that i simply cannot remember :(
Title: Re: string editing question
Post by: Mandoble on 02 Jul 2006, 11:56:47
"+" accepts numbers, arrays or strings, but "-" accepts only numbers or arrays. If you split your strings in parts and add each part to an array, then you'll be able to add or substract strings (array items):

Code: [Select]
_strings = ["I ", "am", "a ", "stupid", " string"]
_msg = ""
"_msg = _msg + _x" forEach _strings
hint _msg
~5
_strings = _strings - ["stupid"]
_msg = ""
"_msg = _msg + _x" forEach _strings
hint _msg
Title: Re: string editing question
Post by: richardedwards on 02 Jul 2006, 20:24:12
nope, that doesnt answer my question at all sorry :(

you are creating an array containing strings, and manipulating the array.

its my fault for making the question too ambigious...i'll rephrase....

_x is an unknown string but its known it contains the word "stupid"

_output is _x minus the word stupid.

I want to perform the action _x = _x - "stupid" and have the remaining resultant display.

As I stated right at the start, there IS a simple, one lined way of doing it....and I simply have forgotten it, so this is really frustrating :( :(
Title: Re: string editing question
Post by: Baddo on 02 Jul 2006, 22:27:44
Are you really sure that you can search for substrings inside strings and remove substrings in OFP scripting language? That would be new to me. As I see it, OFP doesn't give us any functions to do that. But please prove that I am wrong :) I would be happy about that.
Title: Re: string editing question
Post by: Planck on 02 Jul 2006, 23:17:55
Mandoble has given you a way round the fact that there are no string manipulation commands on OFP.

Go with his method, because I don't think there is a better way at the moment.



Planck

Title: Re: string editing question
Post by: bedges on 02 Jul 2006, 23:27:10
just to reinforce that point -

there are no string manipulation commands on OFP.

there are plenty in other programming languages, but sadly ofp isn't one of them. arrays it can manipulate, but not strings, hence mandoble's solution being the best option.

as for single-line stuff, are you perhaps thinking about the format command (http://www.ofpec.com/COMREF/index.php?action=list&letter=f#format)? that's about all i can think of that plays with strings and variables...
Title: Re: string editing question
Post by: richardedwards on 03 Jul 2006, 03:21:58
perhaps its my dodgy memory then  ;D

maybe im  transposing memories of myself handling string manipulation on a past delphi project into OFP?

I could have sworn I have performed such an action on OFP..... better lay off the late nights of coffee & coding, its all blurring into one big ;

_RealMemory = ["OFP","Other projects","job","girlfriend"]
_PercievedMemory = _RealMemory select random ((count _RealMemory)-1)




somebody email a complaint to BiS and see if ArmA can include this functionality ;)