Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

[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.

 

  • Author

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.