Похожие чаты

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 ответов

4 просмотра

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.

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

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

Всем привет, написал код ниже, но он выдает сегфолт, в чем причина? #include <stdio.h> #include <stdlib.h> #include <string.h> struct product { char *name; float price; };...
buzz базз
32
Хотел бы спросить у знающих, правильную ли я выбрал книгу для начала изучения ассемблера Юрова В.И ? Или есть более лучшие книги для начала обучения?
Botsman
25
Добрый день, не подскажите, если в OC-V3 поменять страндартную директорию /storage/ на /storage2/ - не будет сильно много проблем ?
Max Dubovsky
32
Conversation at a festival with a non-crpto person (not a normie by any stretch, though): * person: tell me about crypto, me: ok, the original idea is p2p sound money for the...
molecular#123 🐓
25
Книга Юрова В.И пойдёт для обучения?
Botsman
24
$params = [ 'formid' => 'feedbackForm', 'formTpl' => '@CODE: <form class="form-validate" data-id="ajax_form"> <fieldset class="margin-bottom-md"> ...
Pathologic
1
> Примечательно, что новый владелец удаляет из GitHub любые жалобы, указывающие на подозрительную активность или смену владельца, и, видимо, рассчитывает на то, что пользовате...
Alex Sherbakov
1
I bought some PHA tokens on Kucoin, which is the best wallet to store and easy to use?
AMR
19
'frakturBold' => ['𝖆', '𝖇', '𝖈', '𝖉', '𝖊', '𝖋', '𝖌', '𝖍', '𝖎', '𝖏', '𝖐', '𝖑', '𝖒', '𝖓', '𝖔', '𝖕', '𝖖', '𝖗', '𝖘', '𝖙', '𝖚', '𝖛', '𝖜', '𝖝', '𝖞', '𝖟', '𝕬', '𝕭', '𝕮', '𝕯'...
Roma
4
Подскажите пожалуйста, а я могу вот такую штуку использовать? rpc, только реализованное в реббите https://www.rabbitmq.com/tutorials/tutorial-six-php ( или https://habr.com/ru...
Artyom
11
Карта сайта