lectus Messages: 329 Registered: September 2006 Location: Brazil
Senior Member
Hi!
I don't know if there's a ready function for that in U++.
But this is how I would do this:
1) Read the full contents of the docedit into a String.
2) Create a function to go concatenating characters until it finds \n. Then it adds this line to the array. Do this until the_string.GetLegnth() is reached. At the end return the array.
Here's the sample code:
// Adds each line of a DocEdit to an array
Array<String> DocEdit2Array(DocEdit& d)
{
String s = d.GetData();
Array<String> result;
String line = "";
for(int i = 0; i < s.GetLength(); i++)
{
if(s[i] != '\n')
line += s[i];
else
{
result.Add(line);
line="";
}
}
result.Add(line);
return result;
}
// Event of button click to test the function
void test::ButtonClicked()
{
Array<String> a = DocEdit2Array(docedit1);
for(int i=0; i < a.GetCount(); i++)
{
DUMP(a.At(i));
}
}
Thanks lectus and navi for your suggestions.
I will try it out. But isn't there any limit to string length as I will be having few thousands of lines in docEdit.
Also, please suggest which method to use for appending new lines in docEdit.
navi Messages: 107 Registered: February 2012 Location: Sydney, Australia
Experienced Member
prizzly wrote on Thu, 13 December 2012 07:21
But isn't there any limit to string length as I will be having few thousands of lines in docEdit.
I think U++ makers will be able to answer it best. I couldn't find anything on the manual but I would assume U++ String will be something similar to C++ std::string about which are the following comments found.
... There is no official limit on the size of a string. The software will ask your system for memory and, as long as it gets it, it will be able to add characters to your string...
... The only practical limit on string size in c++ is your available memory...
... std::string::max_size() will tell you the theoretical limit imposed by the architecture your program is running under. Other than that, as long as you have sufficient RAM and/or disk swap space, you can have std::strings of huge size...
prizzly wrote on Thu, 13 December 2012 07:21
Also, please suggest which method to use for appending new lines in docEdit.
// assuming your LineEdit Ctrl is called myLineEditCtrl
// i will do something like this:
String tmpStr(myLineEditCtrl.Get());
tmpStr<<"\nThis is a new line";
myLineEditCtrl.Set(tmpStr);
dolik.rce Messages: 1789 Registered: August 2008 Location: Czech Republic
Ultimate Contributor
navi wrote on Thu, 13 December 2012 14:34
prizzly wrote on Thu, 13 December 2012 07:21
But isn't there any limit to string length as I will be having few thousands of lines in docEdit.
I think U++ makers will be able to answer it best. I couldn't find anything on the manual but I would assume U++ String will be something similar to C++ std::string about which are the following comments found.
I'm not a U++ maker, but I'm pretty sure that String is limited by size of int type, that is 2 Gb, so no problem for usually displayed files If you need to display anything longer, you'd have to use streaming or something similar anyway...