Ecere SDK/eC Forums
http://ec-lang.org/community/
Print view

DynamicString.concatf,concatx
http://ec-lang.org/community/viewtopic.php?f=1&t=377
Page 1 of 1
Author:  samsam598 [ Fri Oct 04, 2013 2:40 am ]
Post subject:  DynamicString.concatf,concatx

Given below code,MessageBox.contents wants to fetch all lines input from editBox1 and a "\n" to separate them line by line.DynamicString.concat(String) works as expected,but for concatf and concatx,maybe I was totall wrong.I just want to concat all inputs into DynamicString buffer.My attempt failed anyway.Help would be appreicated.

PS:don't know why first "\n" in editBox2.AddS shows correct ,but all the rest "\n" show as "|.n" here in the post.

Code: Select all

 
import "ecere"
import "DynamicString"
static DynamicString buffer{};
class Form1 : Window
{
   caption = "Form1";
   background = formColor;
   borderStyle = sizable;
   hasMaximize = true;
   hasMinimize = true;
   hasClose = true;
   size = { 440, 204 };
   anchor = { horz = -31, vert = -68 };
 
   DynamicString str{};
   Button button1 
   {      
      this, caption = "Get", altG, isDefault = true, size = { 90, 29 }, anchor = { left = 48, bottom = 19 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         //char howmany[1024];
         //buffer=DynamicString{};
         str=editBox1.contents;
         //String str=editBox1.contents;
         editBox2.AddS(str);
 
         editBox2.AddS("\n");
         //buffer.concat(str);
         //buffer.concatf("%s\n",str);
         //buffer.concatx(str,"",str,"\n");
         //buffer.concatx(buffer,str,"\n");
         buffer.concatf("%s",str," ",str);
         editBox2.SetViewToCursor(true);
         Update(null);
         //this.Update(0);
         //delete str;
         MessageBox{contents=buffer}.Modal();//CopyString(buffer);
         return true;
      }
   };
   Button button2 
   {
      this, caption = "Exit", escape, size = { 82, 29 }, anchor = { right = 38, bottom = 19 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         Destroy(0);
         return true;
      }
   }
   EditBox editBox1 { this, caption = "editBox1", size = { 382, 19 }, anchor = { left = 24, top = 16, right = 26 } };
   EditBox editBox2 { this, caption = "editBox2", anchor = { left = 24, top = 56, right = 26, bottom = 61 }, hasVertScroll = true, multiLine = true }
 
   bool OnPostCreate(void)
   {
      editBox1.Activate();
      return true;
   };;
}
 
Form1 form1 {};
 
 
Author:  jerome [ Fri Oct 04, 2013 5:23 pm ]
Post subject:  Re: DynamicString.concatf,concatx

Hi Sam,

DynamicString::concatf works like printf so I assume that instead of:

buffer.concatf("%s",str," ",str);

You meant:

buffer.concatf("%s %s",str, str);

To add the string twice with a space in between.

The other problem here is that you're giving concatf a DynamicString object but %s format specifier expects a char * (or String which is equivalent right now).

buffer.concatf("%s %s",(String)str, (String)str);

This will ensure the proper conversion properties are invoked.

For concatx, buffer.concatx(str, " ", str); this should work, except that DynamicString is missing stringification methods so it shows up with a bunch of commas instead (The default Array behavior that DynamicString inherits from)

If you add to the DynamicString class:

Code: Select all

char * OnGetString(char * tempString, void * fieldData, bool * needClass)
{
   return array;
}
 
bool OnGetDataFromString(char * string)
{
   this = (DynamicString)string;
}
That should solve that issue.

Regards,

-Jerome
Author:  samsam598 [ Sat Oct 05, 2013 4:50 am ]
Post subject:  Re: DynamicString.concatf,concatx

Thanks.Yes,perfect.
All times are UTC-05:00 Page 1 of 1