So to convey my point in a more structured manner (you know as we normally do in the trade) take the following snippet of code from an apache velocity template
#set($string = "BB XL|BatikhaSafra|BeingWeird")
#foreach($ramble in $string.split("|"))
$ramble
#end
The output expected should be:
BBXL
BatikhaSafra
BeingWeird
Yet in reality what was happening was that the output was something along those lines:
B
B
X
L
|
B
A
...
Hmmmm, something just doesnt feel right, I wonder what it is. Well needless to say, narcassit me just had to find out the solution on their own.
Well .. after around no less than 3 hours of excavation it turns out that the “|” is a java metacharacter and it was actually splitting over empty strings, something like this:
#foreach($ramble in $string.split(""))
$ramble
#end
Sucks …
The solution was then to escape it (as you do…). So here is the final unadultrated code:
#set($string = "BB XL|BatikhaSafra|BeingWeird)
#foreach($ramble in $string.split("[|]"))
$ramble
#end
Talk about pipe streaming! (lame I know)
haha censored
LikeLike
atleast thats what the super injunction is saying anyways …
LikeLike
Pingback: If Google went down, would you still be able to code? | batikhasafra