Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Looking for examples to split string into container
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
mirek is currently offline  mirek
Messages: 14267
Registered: November 2005
Ultimate Member
Oblivion wrote on Wed, 28 October 2020 19:07
HEllo 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; });
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Vector a user defined struct for XML persistency
Next Topic: Convert struct to string and reconstruct a struct from string
Goto Forum:
  


Current Time: Tue Aug 26 00:32:06 CEST 2025

Total time taken to generate the page: 0.06022 seconds