scala - Extract string of "length x breadth" into different arrays -


i have string with multiple length , breadth in format length x breadth separated commas like

300x250, 720x220, 560x80

i convert 2 separate arrays 1 containing length , breadth.

expected output

length = array(300,720, 560)

breadth = array(250, 220, 80)

any novel way achieve it?

using unzip on tupled values, follows,

val dims = "300x250, 720x220, 560x80"  dims.split("\\w+").map {    s => val array(a,b,_*) = s.split("x")         (a.toint,b.toint) }.unzip 

note first split fetches words without need trimming additional blank characters. in second split extract first , second elements of resulting array.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -