CritiqualError Posted January 31, 2016 Posted January 31, 2016 [i am using Eclipse and Forge 1.8] I was wondering how to take certain characters from a string. Example: I convert the number 123456 to a string then I want to assign every 2 characters to a variable: a="12" b="34" c="56". Like that. How would I go about doing that? Or maybe have it start from the end, so it can be like, 12345678 and end up like: a="1234" b="56" c="78". only splitting them between those 3 groups, the a group allowed to overflow as much as it wants. Quote
gellegbs Posted January 31, 2016 Posted January 31, 2016 strings go in "12345" numbers like 12345 Quote
CritiqualError Posted January 31, 2016 Author Posted January 31, 2016 strings go in "12345" numbers like 12345 Did you even read it? its called converting an integer to a string. Quote
CritiqualError Posted January 31, 2016 Author Posted January 31, 2016 Thanks a bunch. It is very nice to know that I can rely on the forums when I'm stuck on a problem. Such a swift response. I also now know new coding (i coded a bit in other programs so I kinda get how coding works, just this minecraft stuff is rather new to me) I will put this to good use and see what I can do. First let's create a splitter (from the Guava library) with the characteristics we want: static Splitter splitter = Splitter.fixedLength(2).limit(3); For your first problem: List<String> split = splitter.splitToList("12345678"); // returns [12, 34, 5678] For the 2nd one: List<String> split = Lists.reverse(Lists.newArrayList(splitter.split(StringUtils.reverse("12345678")))); // StringUtils is from Apache Commons Lang split.replaceAll(StringUtils::reverse); // returns [1234, 56, 78] Both libraries mentioned above are shipped with Minecraft. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.