Home   Help Search Login Register  

Author Topic: getting letters from string  (Read 1606 times)

0 Members and 1 Guest are viewing this topic.

Offline Surdus Priest

  • Members
  • *
  • Only I can Forgive You!
getting letters from string
« on: 05 Dec 2007, 17:43:28 »
is there a way of for example, getting the letter 'h' into an array from the word 'hello'?

EDIT: another solution to what i am doing would be to know how to cut a string to the length of a set number of characters from the beginning.
« Last Edit: 05 Dec 2007, 17:57:25 by Surdus Priest »
Campaigns are hard, I'll stick with scripting for now!

Offline Trexian

  • Members
  • *
Re: getting letters from string
« Reply #1 on: 05 Dec 2007, 19:06:45 »
Sic semper tyrannosauro.

Offline Surdus Priest

  • Members
  • *
  • Only I can Forgive You!
Re: getting letters from string
« Reply #2 on: 05 Dec 2007, 19:40:32 »
that looks quite good.  its unfortunate that BIS didnt include functions like this.  but anyways, since kron made other good scripts like ups, i cant feel bad about not coming up with something like this myself :D

edit:

i have tried it out and it works very well.  however, it causes a lag from processing so many strings into an array.
i can change this by putting a sleep of 0.001 seconds in the foreach loop. but is there a more effective way of making it process faster?  or do i simply have to put up with the delay until BIS are kind enough to add some string manipulation tools?
« Last Edit: 06 Dec 2007, 02:55:55 by Surdus Priest »
Campaigns are hard, I'll stick with scripting for now!

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: getting letters from string
« Reply #3 on: 06 Dec 2007, 11:38:29 »
The string manipulation "hacks" are quite CPU intensive, which is why they are mostly used by dialog code (where the FPS is a lot less critical). You should be avoiding doing a lot of string processing if you can help it outside of dialogs, but unless you are taking user input, you can usually avoid doing any string processing anyway. If you are doing a large amount of string processing at run time (rather than pre-preparing it at init time), then you may also have to rethink your design.

A for loop with sleep of 0.001 is no faster than a waitUntil loop (it iterates once per frame). If you want to increase the number of string operations you do per second, without doing then all in a block, then only sleep every 10 loops (or whatever).
« Last Edit: 06 Dec 2007, 11:40:32 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Surdus Priest

  • Members
  • *
  • Only I can Forgive You!
Re: getting letters from string
« Reply #4 on: 06 Dec 2007, 13:26:56 »
well, i had already considered pre-processing them in the init. unfortunately that doesnt work, and it must be activated in another script with a 0.01 second delay after the initiation.

i have removed the sleep 0.001 for this because for some reason it thinks theres an error.

also, to do this i have to create a global for each string, which isnt 2 bad i guess, but i do nowadays try to avoid globals as much as possible, which leads me to ask; how many globals can you get away with keeping during a game before saved games become unstable?

edit: im making a dynamic letter-by-letter hint script, and i needed to get and array of strings to do it.

although so far it all looks a bit overkill, its does look very nice now.
« Last Edit: 06 Dec 2007, 13:38:29 by Surdus Priest »
Campaigns are hard, I'll stick with scripting for now!

Offline Loyalguard

  • Former Staff
  • ****
Re: getting letters from string
« Reply #5 on: 15 Dec 2007, 23:17:48 »
I was poking around the recent changes page in the Biki today and found some new scripting commands that may accompany 1.09:

http://community.bistudio.com/wiki/toString
http://community.bistudio.com/wiki/toArray
http://community.bistudio.com/wiki/toUpper
http://community.bistudio.com/wiki/toLower

So perhaps we'll get some non-"hack" string functions with the new patch!!!

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: getting letters from string
« Reply #6 on: 15 Dec 2007, 23:26:41 »
This is true, however they are limited functions and cannot do what some people would like in string functions.

Converting a string to either upper or lower case, or converting a string to ASCII decimal coding or vica versa is all that these functions provide.

Which is nice in itself anyway.   :cool2:

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

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: getting letters from string
« Reply #7 on: 15 Dec 2007, 23:49:08 »
Aha, so now we have another worthless set of new commands  :whistle:

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: getting letters from string
« Reply #8 on: 16 Dec 2007, 00:10:30 »
Well, although they are limited, they could be used to create most, if not all, usual, string manipulation functions. Wouldn't be as nearly as efficient as if they were native, but considerably better than the crazy, though inspired, workarounds used now. Still, unnecessary work for one of us...
E.g.
Code: [Select]
_strLen = { count (toArray (_this select 0) )};
_length = ["hello!"] call _strLen;
« Last Edit: 16 Dec 2007, 00:12:13 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: getting letters from string
« Reply #9 on: 18 Dec 2007, 16:04:16 »
I agree with spooner. These functions could be easily wrapped to produce some basic string functions such as left, right, mid and len. Convert string to array. Operate on array. Convert back to string. Actually, if these commands are fast enough, they could open some exciting possibilties.

The most important function would be an efficient substring matching function.
« Last Edit: 18 Dec 2007, 16:07:10 by Mr.Peanut »
urp!

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: getting letters from string
« Reply #10 on: 18 Dec 2007, 16:41:08 »
Aye, ....Is 'nut' in 'peanut'.


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