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 » Community » Newbie corner » docEdit /lineEdit to array
icon5.gif  docEdit /lineEdit to array [message #38309] Sun, 09 December 2012 19:29 Go to next message
prizzly is currently offline  prizzly
Messages: 2
Registered: December 2012
Junior Member
Hi guys
I am new to upp so need some of your expert advise.
How can i store each lines of docEdit /lineEdit to an array and vice versa.
Thanks

[Updated on: Sun, 09 December 2012 19:39]

Report message to a moderator

Re: docEdit /lineEdit to array [message #38338 is a reply to message #38309] Tue, 11 December 2012 14:26 Go to previous messageGo to next message
lectus is currently offline  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));
	}
}

[Updated on: Tue, 11 December 2012 14:30]

Report message to a moderator

Re: docEdit /lineEdit to array [message #38339 is a reply to message #38309] Tue, 11 December 2012 16:32 Go to previous messageGo to next message
navi is currently offline  navi
Messages: 107
Registered: February 2012
Location: Sydney, Australia
Experienced Member
Beware that LineEdit::Get() on Win32 platform returns "\n\r" as like break not "\n". There is a function Split() exist that is able to break string using delimiter and retuns vector of string. Also Filter() can be use to clean up "\r". see this
http://www.ultimatepp.org/forum/index.php?t=msg&&th= 7064&goto=37872#msg_37872
and this
www.ultimatepp.org/forum/index.php?t=msg&goto=10491

[Updated on: Tue, 11 December 2012 16:38]

Report message to a moderator

Re: docEdit /lineEdit to array [message #38343 is a reply to message #38339] Tue, 11 December 2012 20:15 Go to previous messageGo to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
navi wrote on Tue, 11 December 2012 10:32

Beware that LineEdit::Get() on Win32 platform returns "\n\r" as like break not "\n". There is a function Split() exist that is able to break string using delimiter and retuns vector of string. Also Filter() can be use to clean up "\r". see this
http://www.ultimatepp.org/forum/index.php?t=msg&&th= 7064&goto=37872#msg_37872
and this
www.ultimatepp.org/forum/index.php?t=msg&goto=10491


Thanks for reminding me of Split(). Very handy function!
Re: docEdit /lineEdit to array [message #38379 is a reply to message #38309] Thu, 13 December 2012 07:21 Go to previous messageGo to next message
prizzly is currently offline  prizzly
Messages: 2
Registered: December 2012
Junior Member
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.
Re: docEdit /lineEdit to array [message #38392 is a reply to message #38379] Thu, 13 December 2012 14:34 Go to previous messageGo to next message
navi is currently offline  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.


http://stackoverflow.com/questions/3649639/limit-on-string-s ize-in-c
Quote:


... 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);
Re: docEdit /lineEdit to array [message #38393 is a reply to message #38392] Thu, 13 December 2012 14:53 Go to previous message
dolik.rce is currently offline  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 Wink If you need to display anything longer, you'd have to use streaming or something similar anyway...

Honza
Previous Topic: Why isn't the data getting inserted?
Next Topic: sessions in Skylark
Goto Forum:
  


Current Time: Fri Apr 26 09:31:10 CEST 2024

Total time taken to generate the page: 0.04958 seconds