Home » U++ Library support » U++ Core » Looking for examples to split string into container
|
Re: Looking for examples to split string into container [message #55310 is a reply to message #55309] |
Wed, 28 October 2020 18:41 ![Go to previous message Go to previous message](theme/default/images/up.png) ![Go to next message Go to next message](theme/default/images/down.png) |
![](https://www.ultimatepp.org/forums/images/custom_avatars/1517.jpg) |
Klugier
Messages: 1077 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello David,
Use global Split function. For more info check following example and read this documentation site.
I think this should be straight forward:
auto numbers = Split("one,two,,three", ','); // <- Type is Vector<String>, Upp::Split if not in namespace
for (const auto& number : numbers) {
// number is string...
}
Klugier
U++ - one framework to rule them all.
[Updated on: Wed, 28 October 2020 18:45] Report message to a moderator
|
|
|
|
Re: Looking for examples to split string into container [message #55313 is a reply to message #55311] |
Thu, 29 October 2020 01:06 ![Go to previous message Go to previous message](theme/default/images/up.png) |
![](https://www.ultimatepp.org/forums/images/custom_avatars/3.png) |
mirek
Messages: 13984 Registered: November 2005
|
Ultimate Member |
|
|
Oblivion wrote on Wed, 28 October 2020 19:07HEllo David,
Klugier already pointed to the right function and interface (Upp::Split).
Upp::Split has a plenty of variants, just check the API docs.
Here is conversion of C# -> to U++ code:
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
String text = "one\ttwo three:four,five six seven";
Cout() << text << "\n";
Vector<String> words = Split(text, [](int c) { return c == ':' || c == '\t' || c == ' ' || c == ',' || c == '.' ? 1 : 0; });
for(const auto& s : words)
Cout() << s << "\n";
}
Best regards,
Oblivion
Variation just to demonstrate findarg:
Vector<String> words = Split(text, [](int c) { return findarg(c, ':', '\t', ' ', ',', '.') >= 0; });
|
|
|
Goto Forum:
Current Time: Sun Jun 16 13:47:49 CEST 2024
Total time taken to generate the page: 0.02778 seconds
|