Home   Help Search Login Register  

Author Topic: string editing question  (Read 1079 times)

0 Members and 1 Guest are viewing this topic.

richardedwards

  • Guest
string editing question
« 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 :(

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: string editing question
« Reply #1 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

richardedwards

  • Guest
Re: string editing question
« Reply #2 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 :( :(

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: string editing question
« Reply #3 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.

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: string editing question
« Reply #4 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

I know a little about a lot, and a lot about a little.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: string editing question
« Reply #5 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? that's about all i can think of that plays with strings and variables...

richardedwards

  • Guest
Re: string editing question
« Reply #6 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 ;)