Похожие чаты

Ehi guys, I'm trying to automatically put quotation marks for

each word in a string.
For instance:

code: string = "How you guys doing";
out.println(string);

output: "How" "you" "guys" "doing"

I thought about putting my code in a String and making a method that puts a quotation mark every time it sees a space. But I don't really know how to make such method. Is there any library for this? Any other idea?

Thanks.

6 ответов

9 просмотров

Have you tried regex and groups ?

ᵈᵉᵈ- Автор вопроса
Silam ඞ
Have you tried regex and groups ?

nope didn't hear about them yet. I Googled them, and they seems to fit my need. Thanks!

Regex is probably the easiest. But to learn more, here is a alternative to try out: -> Split the string -> Use Collectors.joining() and a stream() where you first use a map() to manipulate each string and add the ".

ᵈᵉᵈ
nope didn't hear about them yet. I Googled them, a...

classic regex (through pattern, matcher, groups, etc) would be definitely an overkill here. and based on the task and your thoughts about it, I assume that you're at the beginning of your road of learning java. and that's more important reason to not dive into regex. for now. I suggest you to conentrate on java's main features, fundamental ones like loops, flow control constructs, etc., OOP, main sdk classes. and only after that (or even later) dive into regular expressions. just don't switch your focus to regular expressions, concentrate on fundamental stuff. for this task it's enough 3 simple things: - String.split(String regex) method which allows split one string into pieces by provided delimiter. yeah, it actually accepts regex, but for simple cases like that it works same as delimiter, so in your case delimiter is a single space string - " " - for loop or foreach loop - and + operator that works on strings As an example (I assume that you're already familiar with arrays): String text = "several__words__go__here"; String delimiter = "__"; String[] words = text.split(delimiter); // voila, you have array of words of the original text String word = "one"; String modified = "prefix-" + word + "-suffix"; Hm... maybe this example is too obvious. Hope it will be more helpful than harmful. Here's first google result with examples for String.split() method: https://www.baeldung.com/string/split

ᵈᵉᵈ- Автор вопроса
Dmytro Buryak
classic regex (through pattern, matcher, groups, e...

Thank you!!! I really appreciate this so much. And yes, I'm still at the beginning, I started learning GUI only 2 days ago.

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта