How do I split these strings?
If I have these inputs, wich could be random numbers.
How do I split the string into two parts where the middle "-" is the where the split happens?
I will use the splits in a fraction calculator.
"2/3 - 2/-3"
"2/-3 - 2/3"
"2/3 - 2/3"
"-2/-3 - 2/-3"
31 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Is there anyway to split the string in only two items?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Ok, but if the string is "4523/-43 - 423/5542"
Im kinda stuck because these inputs are userinputs
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
okey, thanks. i
i'll try to search for the "-" in the middle somehow 😛 thanks
You can limit the amount of splits by giving an int as secondary parameter in the split function
That way it wil only split on the first occurance of that character
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Exactly.
<:Remi_WTF:1007450914648490014>
Ehm
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
The "-" in the middle is used as a operator.
or will be used as an operator.
Can you change the separator?
@Lurch No It will not have space hyphon space. thats just how i wrote it, im sorry.
ex :
input = 2/-3-2/3
The middle "-" is where i need the split to occure.
A separator should only occure where you want it to be separated, which is not the case here
So separating wont be easy
hmmm.. ok.
If you can change the separator i would change it to something like &
Then you can use the split function
If you can't change it then there's not really a reliable method that I'm aware of to split it
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Ok, thanks ! 🙂
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
i'll try that, thanks for the help. ! 🙂
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Bruh Tuple in current year
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
rip speed
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
because Tuple is an actually completely unnecessary allocation
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
ValueTuple
is the modern equivalent
it's a struct unlike Tuple
, so it doesn't allocateUnknown User•3y ago
Message Not Public
Sign In & Join Server To View