Xorifelse
I'd love to elaborate about discussions...........
- Reaction score
- 87
Introduction:
This system is designed to handle string reading/parsing data easier.
It can also shorten down your code when you're looping through a string.
It also makes your script easier to read.
However, if you want to use this you must use the NewGen editor.
The Actual System:
Explanation:
This struct has a couple of methods/variables which you can use.
Summary:
This might perhaps be a simple script, but its sure as hell easy to use.
I find this much simpler then the normal looping of strings.
This system is designed to handle string reading/parsing data easier.
It can also shorten down your code when you're looping through a string.
It also makes your script easier to read.
However, if you want to use this you must use the NewGen editor.
The Actual System:
JASS:
library Plode
globals
constant integer PLODE_MAX_SIZE = 256
endglobals
struct plode
integer size
integer count = 0
integer pos = 0
string chr
string original
string array char [PLODE_MAX_SIZE]
method next takes nothing returns boolean
set .chr = .char[.count]
set .pos = .count
set .count = .count + 1
if .count > .size then
return true
endif
return false
endmethod
method implode takes nothing returns string
return .original
endmethod
static method explode takes string s returns plode
local plode p = plode.create()
local integer i = 0
local integer l = StringLength( s )
set p.size = l
set p.original = s
loop
exitwhen i > l
set p.char<i> = SubString( s, i, i + 1 )
set i = i + 1
endloop
return p
endmethod
endstruct
endlibrary</i>
Explanation:
This struct has a couple of methods/variables which you can use.
- size - The stringlength of the string exploded.
- pos - The position of the current character in the string.
- chr - The current character.
- next() - This method sets the above variables to their next in line new value.
- explode( str ) - Explode a string by every character which enables you to scan a string quickly.
- implode() - This method is the original exploded string. It isn't really "imploding" but I meanly added it because its a part of "im/ex" plode.
JASS:
scope PlodeExample initializer init
globals
constant string ALPHABET = "abcdefghijklmnopqrstuvwxyz"
endglobals
private function init takes nothing returns nothing
local plode p = plode.explode( ALPHABET )
loop
exitwhen p.next()
call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, p.chr + " is the " + I2S( p.pos ) + "039;th character in the string." )
endloop
call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, "And the original string is: " + p.implode() )
call p.destroy() // Important if you're not using it anymore.
endfunction
endscope
Summary:
This might perhaps be a simple script, but its sure as hell easy to use.
I find this much simpler then the normal looping of strings.