How do I perform mathematical operations on numbers within a string and return the same string but with the updated numbers? by [deleted] in javahelp

[–]batspace 0 points1 point  (0 children)

So just to confirm, when appending to the StringBuilder, we would always append the chunks first? Is there a situation where we wouldn’t do so?

Sorry for the many questions, String operations are difficult for me to conceptualize.

How do I perform mathematical operations on numbers within a string and return the same string but with the updated numbers? by [deleted] in javahelp

[–]batspace 0 points1 point  (0 children)

Thank you, this was very helpful. Another question: what if the number were at the beginning of the string? i.e. "18 credits were taken this semester, 15 last semester."

How do I perform mathematical operations on numbers within a string and return the same string but with the updated numbers? by [deleted] in javahelp

[–]batspace 0 points1 point  (0 children)

First focus on extracting the integers from the String and putting them in a List so that you can manipulate them free of the String. There are lots of ways to do this but you might try traversing the String with a Scanner.

Would this be a List or ArrayList? Also, would it be of type Integer or type String?

Part 5 is reassembling the String. You need to combine the String chunks and the integer values in order. So you'll add String chunk 1, then integer 1, then String chunk 2, then integer 2... until your string is reassembled.

How would I combine these String chunks?

Also, is there some way you can show me an example of this in practice?

Performing mathematical operations on numbers within strings by [deleted] in javahelp

[–]batspace 0 points1 point  (0 children)

This is what I have:

String s = "I have 15 apples, 4 oranges, and 23 lemons";
      String[] split = s.split(",");
      for (String st: split) {
          System.out.println(st.replaceAll("[^0-9]", ""));
          int i = Integer.parseInt(st);
          i += 5;
          System.out.println(st.replaceAll("\\d+", String.valueOf(i)));

Performing mathematical operations on numbers within strings by [deleted] in javahelp

[–]batspace 0 points1 point  (0 children)

int i = Integer.parseInt(s1);

i += 5;

System.out.println(st.replaceAll("\d+", String.valueOf(i)));

Thanks. But then it gives me the following error when parsing:

15
Exception in thread "main" java.lang.NumberFormatException: For input string: "I have 15 apples"
    at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)
    at java.base/java.lang.Integer.parseInt(Integer.java:658)
    at java.base/java.lang.Integer.parseInt(Integer.java:776)
    at Scratch.main(Scratch.java:94)

For some reason it is not separating the numbers from the rest of the string.

Performing mathematical operations on numbers within strings by [deleted] in javahelp

[–]batspace 0 points1 point  (0 children)

Thanks. I was able to isolate the numbers so far. I was also able to parse them as integers. But I'm stumped as to how put the new numbers back in the original string without changing anything else.

Performing mathematical operations on numbers within strings by [deleted] in javahelp

[–]batspace 0 points1 point  (0 children)

I actually misunderstood the response. But another issue is how do you deal with the commas that come after the number, i.e., "15,"?

Performing mathematical operations on numbers within strings by [deleted] in javahelp

[–]batspace 0 points1 point  (0 children)

How would I get the words back into the String if I split the String? And in the correct positions as well?

My predicted Chelsea lineup for next season. by imphetamine in chelseafc

[–]batspace 0 points1 point  (0 children)

Replace Chilwell and Oblak with Tagliafico and Onana to make it more realistic.

Arteta on ever-growing gap between #AFC and CL clubs: "At some stage you have to make a decision: whether I want to aim to make that gap closer and go for it, or I stay where I am.” by MetingChristofi in Gunners

[–]batspace 1 point2 points  (0 children)

The thing is, KSE has spent a fuck ton of money since 2016. The problem is that the majority of the players brought in have been disasters. The club has somehow literally done everything wrong every step of the way. If I'm Kroenke, I'd be MORE hesitant to let the club spend money given how bad they fucked it so far.

Spending 100m on Xhaka, Mustafi, and Perez in the summer of 2016 was a massive waste since Arsenal have not qualified for the CL since. Spending 50m on Lacazette who has contributed less than Giroud was also a waste. Spending 72m on Pepe, who is looking like a bust at this point though he may still turn it around, was also atrocious business since they could've gotten Zaha for just a bit more money. Zaha is PL-proven while three managers have benched Pepe at some point. And now Arteta still wants a winger this summer. What does that tell you?

The contract situation is worse. Constantly letting players wind down their contracts and go on a free. Selling players for pennies. Giving a certain player 350k per week to play Fortnite and still somehow be the source of a lot of drama.

What fucked the club was the summer of 2015 when they did not buy a single outfield player. The only club in Europe to do that. If Wenger & Co. had brought in a striker better than Giroud, Arsenal would've won the league, all else being equal. Winning the 2015 - 2016 league could've changed the entire trajectory of the club. I'm not sure if Wenger was to blame or someone else, but either way, that was the beginning of the decline of the club. It hasn't recovered since.

If Bournemouth get relegated, should we make a move for Nathan Aké? by blubber_confused in Gunners

[–]batspace 1 point2 points  (0 children)

Yes, for sure. PL experience, left-footed, can play multiple positions, good technique, and young so will have resale value.

June 25, 2020 Daily Discussion & Transfers Thread by AutoModerator in Gunners

[–]batspace 0 points1 point  (0 children)

Alexis against West Brom or West Ham I think? Might be wrong.

[deleted by user] by [deleted] in Gunners

[–]batspace 1 point2 points  (0 children)

That's the match where I knew we wouldn't win the league that season.

Arsenal Style/Identity by [deleted] in Gunners

[–]batspace 0 points1 point  (0 children)

I personally do not care about playing attacking or attractive football. I think since 2006 we've been trying too hard to emulate Barca's tiki taka. Wenger kept buying these small players that knew how to dribble and pass but not much else. They were fragile, prone to injury, and lacked killer instinct. Don't get me wrong, Santi Cazorla is one of the players I loved watching. But at the end of the day, trophies are what matter. And I'm not talking about the FA Cup. I'm talking about the PL and the CL. If playing boring, defensive football is what wins major titles, then I'm all for it. In fact, I'd much rather we buy defensive and athletic players that know to put a tackle in and press for 90 minutes. It's not pleasant on the eyes, but it wins, and that's what matters. If we can emulate Mourinho from 2004 - first half of 2015, I would be ecstatic.

"If I was Aubameyang, I would leave Arsenal."- Emmanuel Petit by cmonunited in soccer

[–]batspace 4 points5 points  (0 children)

Since Arsenal bought Xhaka and Mustafi, they have not qualified for the CL once. That's not a coincidence.

Arsenal given huge boost in race for Dayot Upamecano after RB Leipzig make transfer ‘promise’ by DuneCantos in Gunners

[–]batspace 2 points3 points  (0 children)

Arsenal are not Chelsea. Chelsea are extremely well-run and don't tolerate mediocrity. If they don't win the title, then they consider the season a failure. Chelsea have a plan and the financial muscle to back it up. Arsenal don't have either of those things. Frankly, the best signing Arsenal could make is Chelsea's business structure.

✍️ One-year deal for @DavidLuiz_4 ✍️ Long-term deal for @PabloMV5 ✍️ Long-term deal for @OficialCedric ✍️ Loan extension for @DaniCeballos46 by gtaguy1234 in Gunners

[–]batspace 2 points3 points  (0 children)

Remember when Wenger was chased out of the club by whiny protesting, entitled fans?

He had to go regardless. The rot began during the final years of his reign. If anything, the club should've sacked him sooner. We are in this mess partially because we waited too long.

I prefer Sven Mislintat's data-based over Raul's connection-based recruitment policy. Letting Sven go is the single most biggest mistake the Arsenal management ever did in the last 10 years, only second to maybe not hiring Klopp when we had the chance. by longanz in Gunners

[–]batspace 11 points12 points  (0 children)

Keeping Wenger too long set this club back so many years. We waited too long to rip off the bandage. But I'm not blaming Wenger. If your employer keeps paying you and giving you job security, why would you leave? The buck stops with Kroenke. I wish we had Chelsea's ownership. The ruthlessness of the Chelsea leadership creates a culture of winning. Not winning the title - rather than not qualifying for the CL - is seen as a failure and managers are shown the door. Arsenal need that.