Jump to content
  • 0

How do we split strings in java


Question

Posted (edited)

Hi guys,

 

I have a code snippet here:

String str = msgCont.toString();
    String[] strs = str.split("\n");

    if (strs[2].startsWith("partofthemessage") && strs[2].contains("x")) {
        Main.handleDonation("y", strs[2].split("\\)")[0].split("\\(")[1], str.split("xx: ")[1].substring(0, 17), (int)Double.parseDouble(strs[2].substring(57, strs[2].indexOf(" x"))));
");

 

Will someone care to explain if :

 

 

String[] strs = str.split("\n");

    if (strs[2]

 

means the second string of the msg content?

 

 

Thanks!

Edited by mytuo

11 answers to this question

Recommended Posts

  • 0
Posted

The first element of an array is accessible by the value 0. The 2nd element has the position 1.. the 3rd element 2....

array[0] = first element

...

array[2] = 3rd element.

 

The code is hardcoded. Rework it 

  • 0
Posted
10 minutes ago, melron said:

The first element of an array is accessible by the value 0. The 2nd element has the position 1.. the 3rd element 2....

array[0] = first element

...

array[2] = 3rd element.

 

The code is hardcoded. Rework it 

The guy don't even know how to post a code using tag and u tell him something only people with months of knowledge will understand and then to rework it.

 

I would post a clap clap gif but no worth it. Write him down about volatiles too.

  • 0
Posted
19 minutes ago, Kara` said:

The guy don't even know how to post a code using tag and u tell him something only people with months of knowledge will understand and then to rework it.

 

I would post a clap clap gif but no worth it. Write him down about volatiles too.

I could just say array[2] = 3rd element. But I preferred to explain it a bit..

 

Maybe that guy, one day will be better than us :D

  • 0
Posted
1 minute ago, melron said:

I could just say array[2] = 3rd element. But I preferred to explain it a bit..

 

Maybe that guy, one day will be better than us :D

 

We will both dead till that day. Or even worst. You will be father with 3 kids who laugh at your coding and a wife who says STOP using the damn computer and help me do laundry U FUCK!

 

Or u can end up like tryskell. No girlfriend, 1 friend who visit you every 3 months from California and you sit with him for 2 hours to eat french croisons and a freemium girlfriend (If you know what i mean :troll:)

  • 0
Posted (edited)

I appreciate all the attention guys :) Honestly I'm new to Java, that's true and I'm trying to debug the automatic donation system from l2 packs like ava mythras etc. The project is totally local, no publishing, no selling, just wanna get it done. I got to tweaking the source java to :

 

public static void decode(Message msg) throws Exception {
    Object msgCont = msg.getContent();
    String from = msg.getFrom()[0].toString();
    String str = msgCont.toString();
    String[] strs = str.split("\n");
    if (strs[2].startsWith("This email confirms that you have received a donation of") && strs[2].contains("EUR")) {
        Main.handleDonation("Paypal", strs[2].split("\\)")[0].split("\\(")[1], str.split("Confirmation number: ")[1].substring(0, 17), (int)Double.parseDouble(strs[2].substring(57, strs[2].indexOf(" EUR"))));
        return;
    }
    System.out.println("[FATAL] Corrupted donation from:\n->" + from + " (Please check this eMail)");
}

 

 

 

However I still get the exception about the corrupted donation.

 

The system goes into my mailbox, reads the mail but it doesn't decode it correctly.

 

The e-mails come in like this :

 

image.png.54c300172ebcc40cc75e516f71d8a001.png

 

and my understanding is that the 3rd line is exactly what it should be.

 

The function does not even go to Main.handleDonation, it dies at if (strs[2].startsWith, so it must not recognize the text correctly

 

I'm struggling alone on this for 2 days now.

 

Thanks again to people wanting to help :)

 

:D 

Edited by mytuo
  • 0
Posted (edited)

String#split generates an array of String based on the pattern you put as parameter, in your case \n, which is the symbol of new line.

 

An array starts at 0, so a 100 size array goes from 0 to 99, getting the 100th, 101th, etc element would end into IOOBE (index out of bounds exception).

 

To debug such crappy stuff, the easiest is to log each cut element and see if it's supposed to be cut that way.

 

Use

System.out.println(Arrays.toString(strs));

To see how your tokens are generated, if they are correctly formed, etc.

 

You can also put logs into handleDonation to see what the transformed Strings are.

 

@Kara` I got a gf, and I visit my friends (14y of friendship for the oldest) every month for some roleplaying session (I'm the DM).

Edited by Tryskell
  • 0
Posted
9 minutes ago, Tryskell said:

String#split generates an array of String based on the pattern you put as parameter, in your case \n, which is the symbol of new line.

 

An array starts at 0, so a 100 size array goes from 0 to 99, getting the 100th, 101th, etc element would end into IOOBE (index out of bounds exception).

 

To debug such crappy stuff, the easiest is to log each cut element and see if it's supposed to be cut that way.

 

Use


System.out.println(Arrays.toString(strs));

To see how your tokens are generated, if they are correctly formed, etc.

 

You can also put logs into handleDonation to see what the transformed Strings are.

 

@Kara` I got a gf, and I visit my friends (14y of friendship for the oldest) every month for some roleplaying session (I'm the DM).

 

Plz tell me SweeTs is dressed like anime girl and i quit maxc forever.

  • 0
Posted
On 3/18/2019 at 3:56 AM, mytuo said:

Honestly I'm new to Java,

 

The system goes into my mailbox, reads the mail but it doesn't decode it correctly.

 

:D 

Paypal prvovides IPN (instant payment notification) when a payment is done paypal notifies a given link with the payment details, after that you validate and proceed to save the information into database, then you handle how you will distribute it into your java code read (SELECT FROM etc...) and then reward.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • ⚔️ WELCOME TO L2EPICFAIL ⚔️ Server developed by gamers, for gamers! ❄️ WINTER SEASON #8 ❄️ OPEN BETA — 15 NOVEMBER 2026 GRAND OPENING — 20 NOVEMBER 2026, 18:30 GMT+0 Website: https://l2epic.fail/ Discord: https://discord.gg/6hwhrkrHBG ━━━━━━━━━━━━━━━━━━━━━━━━━━ ⚔️ SERVER FEATURES & RATES EXP — 10x SP — 9x Adena — 6x Drop — 3x Spoil — 3x Seal Stones — 3x Epic Raid Boss Drop — 1x Regular Raid Boss — EXP 5x / SP 5x / Drop 4x Quest Drop — 1x (selected quests 2–3x) Quest Rewards — 1x (Adena / EXP / SP 3x) ━━━━━━━━━━━━━━━━━━━━━━━━━━ ★ PREMIUM ACCOUNT EXP +20% SP +20% Adena +20% Drop +20% Spoil +20% Quest Rewards +20% Available through voting, Epic Coins or donations. World Chat — 60 messages per day using "&" Buff Book usable outside towns. Premium applies to all characters on the account. ━━━━━━━━━━━━━━━━━━━━━━━━━━ ✨ SPECIAL FEATURES Classic Interface Active Anticheat Vote System Daily Missions Attendance Rewards Masterwork Items Brooches & Diamonds Kamaloka Autofarm Epic Auctioneer Epic Market Price Search No Carrier Protection Raid Rank System PvP Events ━━━━━━━━━━━━━━━━━━━━━━━━━━ 🐉 EPIC BOSSES & RESPAWNS All times GMT+0. Spawn windows visible through .epic. QUEEN ANT — LVL 80 Every day except Wednesday and Sunday 18:00–18:30 Maximum C-grade equipment Boosted HP / Drop Chance 49% CORE — LVL 80 Monday and Friday 20:00–20:15 Maximum B-grade equipment Boosted HP / Drop Chance 60% Core Ring: +1 STR, +1 DEX ORFEN — LVL 80 Tuesday, Thursday and Saturday 20:00–20:15 Maximum B-grade equipment Boosted HP / Drop Chance 60% Orfen Earring: +1 WIT, +1 INT ZAKEN — LVL 80 Monday and Friday 19:00–19:30 Maximum A-grade equipment Automatic PvP Zone BAIUM Every Sunday 18:00–19:00 Automatic PvP Zone / Regular HP FRINTEZZA Tuesday and Thursday 19:00–20:00 Minimum 2 parties / Maximum 5 parties Minimum character level 74 Automatic PvP Zone ANTHARAS Every two weeks on Saturday 19:00–19:30 Automatic PvP Zone VALAKAS Every two weeks on Saturday 19:00–19:30 Automatic PvP Zone Antharas and Valakas spawn on alternating weeks. Epic Bosses drop Epic Medals equal to their level × 10. ━━━━━━━━━━━━━━━━━━━━━━━━━━ 🏆 RAID RANK Clans earn Raid Rank points by killing Raid Bosses level 30+. Raid Bosses level 75+ award 150 points. Rankings reset every Monday morning. Weekly Rewards: 1st Place — 50 RRR Coins 2nd Place — 40 RRR Coins 3rd Place — 30 RRR Coins 4th Place — 20 RRR Coins 5th Place — 13 RRR Coins RRR Coins can be exchanged for Epic Jewelry. ━━━━━━━━━━━━━━━━━━━━━━━━━━ ⚒️ ENCHANT SYSTEM Safe Enchant — +3 Maximum Enchant — +16 Regular Enchant Chance — 60% Blessed Enchant Chance — 66% Enchant chances progressively decrease after +10. ━━━━━━━━━━━━━━━━━━━━━━━━━━ 💎 BROOCHES & DIAMONDS Maximum Level — +10 Brooch Compound Chance — 25% Diamond Compound Chance — 35% Requires two items of the same type and level. On failure, one item remains in inventory. Disabled during Olympiad. ━━━━━━━━━━━━━━━━━━━━━━━━━━ ✨ MASTERWORK ITEMS Masterwork Crafting Chance — 2% A-grade — Armors & Jewelry S-grade — Weapons, Armors & Jewelry ━━━━━━━━━━━━━━━━━━━━━━━━━━ ⚔️ REGULAR RAID BOSSES All regular Raid Bosses have boosted HP. Slightly increased M.Def to give fighters an advantage. Respawn — 24–30 hours Epic Medal Drops — Equal to Raid Boss level Raid Boss status can be checked on the map. ━━━━━━━━━━━━━━━━━━━━━━━━━━ 🏅 OLYMPIAD Weekly Period Thursday–Saturday, 16:00–22:00 GMT+0 Maximum Equipment Enchant — +7 (progressive) Minimum Non-Class Participants — 5 Minimum Class-Based Participants — 10 ━━━━━━━━━━━━━━━━━━━━━━━━━━ 📜 CLASS TRANSFER 1st Class — 50k Adena 2nd Class — 500k Adena 3rd Class — 25kk Adena + 700 Halisha Marks Halisha Marks are tradeable and drop in Shrine of Loyalty. ━━━━━━━━━━━━━━━━━━━━━━━━━━ 👑 NOBLESSE QUEST Retail-style Noblesse Quest with boosted quest drops. Alternative Method — No Barakiel Kill Required Collect 100 Noble Ants Feeler from Wailing of Splendor in Valley of Saints. Drop Chance — 4% Barakiel Respawn — 10–14 hours Barakiel's Chest provides 10 Noble Ants Feeler when the relevant quest is active. ━━━━━━━━━━━━━━━━━━━━━━━━━━ 📖 SUBCLASS QUEST Minimum Main Class Level — 75 Start the Reorin Quest in Giran. Obtain the required item from Cabrio's Chest first. Collect items from Hallate, Kernon and Golkonda. Return to Reorin and complete the remaining quest requirements. Maximum Subclasses — 5 Cabrio Respawn — 6–8 hours Tower of Insolence Raid Bosses — 8–10 hours ━━━━━━━━━━━━━━━━━━━━━━━━━━ 🔮 SKILLS & AUGMENTS Mass Sweep — All Bounty Hunters level 40+ Block Buff — All characters, toggle Escape — 20 seconds, no Scroll of Escape required Automatic Skill Learning Skill Loss After 16 Levels of Delevel Maximum Buffs — 24 + 4 with books Augmentation Skill Chances: Normal Life Stone — 4% Mid-grade Life Stone — 5% High-grade Life Stone — 7% Top-grade Life Stone — 6% Fast Augmentation by double-clicking Life Stones. ━━━━━━━━━━━━━━━━━━━━━━━━━━ 🛒 GM SHOP Weapons, Armors and Jewelry — Up to C-grade Soulshots / Spiritshots — Up to C-grade Mana Potions — 500 MP / 5 seconds ━━━━━━━━━━━━━━━━━━━━━━━━━━ ✨ NPC BUFFER All Buffs, Songs and Dances Third Class Buffs and Resists Buff Duration — 1 Hour Buff Book available to every character. ━━━━━━━━━━━━━━━━━━━━━━━━━━ 🌍 GLOBAL GATEKEEPER All Towns Catacombs and Necropolises Tower of Insolence — Floors 3 / 5 / 7 / 10 ━━━━━━━━━━━━━━━━━━━━━━━━━━ 🛡️ CLANS & PVP Maximum Main Clan Members — 80 Maximum Alliance Clans — 3 Clan Leave / Dismiss Penalty — 12 Hours Epic PvP Zone Limit — 4 CPs / 36 Players Clan skills apply to all members without requiring titles. ━━━━━━━━━━━━━━━━━━━━━━━━━━ ⚙️ AUTOFARM Available to Everyone After the First Week Maximum 1 Active Window per HWID Maximum 1 Hour at a Time Requires Autofarm Tickets purchased with Epic Coins and Adena. Activate using .autofarm Disabled While PvP Flagged Third-Party Bot Software Is Prohibited ━━━━━━━━━━━━━━━━━━━━━━━━━━ 📌 ADDITIONAL FEATURES Maximum 3 Windows per HWID Only 1 Window Allowed in PvP Zones Teleport Protection — 20 Seconds Weight Limit — 10x Stackable Enchant Scrolls and Life Stones Blue Champions — 5x HP Minimum Trade Level — 40 Minimum Chat Level — 20 Arrows and Spellbook Drops Disabled Blacksmith of Mammon and Merchant of Mammon in Towns Alt+Click Buff Removal 19-Level Party EXP Difference No Carrier Disconnect Protection Payback System ━━━━━━━━━━━━━━━━━━━━━━━━━━
    • They're just jealous because I'm better at prompting than all of them combined. There's all working on L2jPromptius and can't even manage to open a single private server with it in like 10 years, and now they're nervous because I'm sharing tools they've been gatekeeping from the community so they can't profit anymore. Truly shameless behavior from them  They're losing business opportunities with every free share, they literally live from the game, just a bunch of unemployed dudes 
    • I don't understand the hate at all? Why are people getting mad at 911reg for sharing an already free tool but improved? Right now the competition is not in dev ability but in creativity and vision. 
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..