Convert string into an array of arrays in javascript
You can use JSON.parse()
and .replace()
to make your string a parsable string like so:
const my_string = "['page1',5],['page2',3],['page3',8]",stringified = '['+my_string.replace(/'/g, '"')+']';
console.log(JSON.parse(stringified));
How to split an array in java or Kotlin?
A simple solution is joining the original array into a string, split by space and then split again into the characters (here in kotlin):
arr.joinToString().split(" ").map{ it.split() }
This is not optimized but still in O(n)
(linear complexity). It benefits from readability which most often should be preferred whereas performance should be addressed if this is critical to your task at hand.
How to store a split string as an array in Java?
in.split(" ", 2)
creates an array of String
elements. Arrays don't generally print easily. Using Arrays.toString()
is a good way to get a nice String
representation of the array object. If you want to store the array object, use the result of in.split(" ", 2)
, and format it as a string only when you need to.
Related Topics
How to Update Constraints Programmatically
Uisearchcontroller Searchbar Delegate Not Working
How to Get Multiple Buttons from a Single Tableviewcell
String to Double in Xcode 6's Swift
How to Create a Custom iOS Keyboard
Uibutton Subclass @Ibaction Not Working
Apple Healthkit - Background Updates Not Triggering
Prevent Uitableview Scrolling Below a Certain Point
iOS + Swift, How to Redirect to Itunes Purchase Page
Avplayer Not Full Screen in Landscape Mode Using iOS Swift
Determine If Mkmapview Was Dragged/Moved in Swift 2.0
Swift: Load Custom Uiview from Xib Programmatically
How to Use Key-Value Coding in Swfit 4.0
Setup a Collectionview with "Tag"-Like Cells
Skspritenode Does Not Let Touches Pass Through When Isuserinteractionenabled False