I'm trying to convert a String of characters that has spaces in it to a BigInteger...and I'm failing. Any help would be greatly appreciated.
8 replies to this topic
#1
Posted 17 December 2010 - 03:56 PM
|
|
|
#2
Posted 17 December 2010 - 04:03 PM
Examples please. And your code.
#3
Posted 17 December 2010 - 04:13 PM
Well, is there a function to remove all spaces from a String? I believe trim() only removes spaces from the beginning and end of the String.
Or am I gonna have to right a loop or something to do it?
Or am I gonna have to right a loop or something to do it?
#4
Posted 17 December 2010 - 04:16 PM
Also, I guess I need to get the characters in the String into digits. Is getBytes going to be the best way to do this?
EDIT: Here's the String:
I'm not necessarily looking for the code. Even if someone could just let me know which functions or type of code (e.g. loop, etc.) would be the best way to do this, I could take it from there.
EDIT: Here's the String:
String message = "The quick brown fox jumps over the lazy dog.";
I'm not necessarily looking for the code. Even if someone could just let me know which functions or type of code (e.g. loop, etc.) would be the best way to do this, I could take it from there.
#5
Posted 17 December 2010 - 08:15 PM
Alright. I actually just ended up using String.getBytes() to convert it into bytes, and then was able to declare a BigInteger with the value from the bytes.
#6
Posted 18 December 2010 - 02:25 AM
anyway to remove all spaces you can use String.replaceAll()
#7
Posted 18 December 2010 - 07:01 AM
An example that removes all whitespaces from the string:
s.replaceAll() takes regex as an argument, so if you are not familiar with them, you should look them up.
String s = "The quick brown fox jumps over the lazy dog.";
s = s.replaceAll("\\s", "");
System.out.println(s);
Results: Thequickbrownfoxjumpsoverthelazydog.s.replaceAll() takes regex as an argument, so if you are not familiar with them, you should look them up.
#8
Posted 18 December 2010 - 07:02 AM
this should work as well:
s = s.replaceAll(" ", "");
#9
Posted 18 December 2010 - 03:52 PM
Thanks for the tip!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









