Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to get ints from a string with whitespace?

Tags:

People also ask

How do you get the numbers from a string separated by space in Python?

split() returns ["1", "15", "163", "132"] for each of these string elements, simply convert them to an integer.

Does parseInt ignore whitespace?

parseInt( ) The function returns an integer parsed from the given string. If the first argument is not a string, it is converted to one automatically using ToString() . Either way, any leading whitespace is ignored.

Can ints be strings?

We can convert int to String in java using String. valueOf() and Integer. toString() methods. Alternatively, we can use String.

Can you add ints to a string Java?

You can use the String concatenation operator + to concatenate integers to a string in a clear and concise manner. Note that the compiler implicitly constructs an intermediate StringBuilder object, append the integers, and then call the toString() method.


I know this is simple, I just can't recall the best way to do this. I have an input like " 5 15 " that defines the x and y of a 2D vector array. I simply need those two numbers into int col and int row.

What's the best way to do this? I was attemping stringstreams, but can't figure out the correct code.

Thanks for any help!