get a wxArrayString as a wxString Topic is solved

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

get a wxArrayString as a wxString

Post by MoonKid »

Example: There are some items in a wxArrayString. I want them all in one string seperated by '\n'. There is now standard way implemented yet.

please see http://forums.wxwidgets.org/viewtopic.php?t=7492 for the previous discussion.

There are some ways I think
1. a cast operator in wxArrayString so it is possible to handle it like a wxString

2. ask wxArrayString for a string of all items (GetAsString())

3. a wxString ctor wxString::wxString(wxArrayString)

4. an other solution?


For me I choose the #2 and patched the wxArrayString class.

What is the official way to get such patches in the official wxWidget source?
Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

Post by Ksmith22 »

Code: Select all

wxString s = "";

for(int i=0;i<arr_str->GetCount();i++)
{
   s << arr_str->Item(i);

   // Don't draw a \n at the end of the string
   if(i != arr_str->GetCount()-1)
       s << '\n';
}
There ya go. It's so easy I don't see why it needs to be written into the class.
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

Post by MoonKid »

Ksmith22 wrote: It's so easy I don't see why it needs to be written into the class.
THATs why I want it in the class. Because I do not want to write such easy things every time!
Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

Post by Ksmith22 »

MoonKid wrote:
Ksmith22 wrote: It's so easy I don't see why it needs to be written into the class.
THATs why I want it in the class. Because I do not want to write such easy things every time!
Make it a function. You only have to write it once.
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

Post by MoonKid »

Ksmith22 wrote:Make it a function. You only have to write it once.
It happend. Now I want to patch it to wxWidgets. ;)
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 »

But what is the use of such a function ?
If you want to write it to file you usually use
a stream, and not a string. So, wxTextCtrl
also has a streaminterface.

For what and how often do you use such a function ?
MoonKid wrote:There are some ways I think
1. a cast operator in wxArrayString so it is possible to handle it like a wxString

2. ask wxArrayString for a string of all items (GetAsString())

3. a wxString ctor wxString::wxString(wxArrayString)

4. an other solution?
to #1: I think thats the worst way, it could leed to unexpected behavoir in your code.

to #2&3: Hm, could be a way, but how often is this needed ? And wheres the sense for it ?
Hm, and for int, float etc ?
Maybe it would make more sense to implement a templatefunction:

Code: Select all

template<class type>wxString Array2Type(type& array,wxString delimeter)
{
// do the stuff
}
phlox
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

MoonKid, I don't know if you read the reactions that are posted thoroughly or not, but I explained WHY it cannot be part of the class here;

http://forums.wxwidgets.org/viewtopic.php?t=7492

Read my reply ..
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
Post Reply