#Split strings discussion

1 messages · Page 1 of 1 (latest)

queen glacier
civic urchin
#

hey

queen glacier
#

ok

feral sluice
#

adds STRING_ARRAY as datatype

civic urchin
#

is that compatible with your other api, (which i'm using) the one for the blocks

feral sluice
#

sure

queen glacier
#

So as far as I understand you have a string like "A☇B☇C" and you want it to be a List "A", "B", "C"

queen glacier
#

did I get that right

#

"A☇B☇C".split("☇")

#

does that not produce the right result?

civic urchin
#

and that will split for every time it finds ☇?

#

or just for the first

feral sluice
queen glacier
#

every

#

(you can limit it with some parameters)

civic urchin
queen glacier
#

The split method has a problem: it breaks when you have a string which contains the separator

#

spaces dont matter?

#

whats so special about spaces

#

spaces are characters

#

newlines are characters

civic urchin
#

i don't know, its the first time i'm trying this

queen glacier
#

"☇" is a character

#

one thing tho

#

if you try and save a "☇" then it obviously breaks

heady pewter
#

Oh

#

DataTypes.list(PersistentDataType.STRING);

#

😎

civic urchin
#

so if i save ☇ to a String on PDC it will break

#

?

queen glacier
#

lets say you have the list:
"A☇G", "B", "C"
and save and restore then you get
"A", "G", "B", "C"

feral sluice
heady pewter
#

The name of the thread is confusing

queen glacier
#

gep i just wanted to escape the gui discussion+

#

i did not bother to think of a name

civic urchin
queen glacier
#

Split strings discussion

queen glacier
#

string.split goes through your string

civic urchin
#

okay tysm

queen glacier
#

and every time it finds the delimeter it splits the string there

feral sluice
civic urchin
#

well actually with your lib i can just save the itemstack

#

lol

queen glacier
#

imagine if you had a string with red markings

#

just cut it at the red markings

feral sluice
#

didnt know you need that

queen glacier
#

(string as in cotton or smth)

#

oh yeah you could also just serialize, but thats a mess

civic urchin
queen glacier
#

yeah no its not like Cs strtok

civic urchin
#

i'm saving data to a block so when i break it i get the item back with all the correct itemmeta's values

#

so i was doing the lore

#

and i stumbled around this problem

#

so thanks, all!

feral sluice
#

then just use DataType.ITEMSTACK and save that inside the block's PDC

queen glacier
#

library is the way to go

#

delimeter based string storage is funny and hacky

#

but I will find your delimeter and break your plugins legs

#

if I ever come on your server

feral sluice
#

as said, this one doesn't use MorePersistentDataTypes but instead manually serializes the itemstack. you can avoid that by using MorePersistentDataTypes, too

civic urchin
#

You have an API for everything 🤣

queen glacier
#

libraries are great

#

researching libraries takes the fun of reading through 30 pages of bukkit docs and crying yourself to sleep away tho