cancel
Showing results for 
Search instead for 
Did you mean: 

Add up two or more texts and show them into 1 Textarea

A.Qasim
Associate II

Greetings,

I am trying to add up texts from different scroll lists and show up in one textArea as a concatenated string as image shown below :-

0693W00000NroScQAJ.bmpI have tried converting the typed text to Unicode::UnicodeChar and then applying Unicode::strncpy but it completely replaces the text.

10 REPLIES 10
Andrew Neil
Evangelist III

You need to show what you've actually done in order for people to be able to comment on why it might not be working.

For strncpy, you would need to be sure that you make the copy destination the NUL termination of the other string...

0693W000008wfhEQAQ.png 

thanks for your reply I'll shortly upload the project

Unicode::strncpy(st1, TypedText(T_RESOURCEID1).getText(), 20); 
Unicode::strncpy(st2, TypedText(T_RESOURCEID7).getText(), 20);
	
*st3 = *st1 + *st2;
Unicode::snprintf(textArea1Buffer, TEXTAREA1_SIZE, "%s", st3);

 in result of this snippet i only get the 1st column value

The other question would be when TouchGFX evaluates the length of the string: could it be that it evaluates it before you do the concatenation, and then only uses that length of the string - so never sees your update ... ?

Hello A.Qasim,

Can you show how you declared your *st3 and also your textArea1 declaration ?

/Osman

Osman SOYKURT
ST Software Developer | TouchGFX

0693W00000NrudMQAR.pnghere i have declared the st3

0693W00000Nruj0QAB.pnghere I have declared values in textArea under prefix heading

Hello A.Qasim,

Ok, first maybe reduce the length of your strings, 50 is too much from what I see of your UI. Secondly, all your st1, st2 and st3 length are 50, so if you do *st3 = *st1 + *st2 it can't fit. So if you want to keep 50 as the length of your st1 and st2, then try with st3[100].

And last remark, have a look at strcat() function ;)

/Osman

Osman SOYKURT
ST Software Developer | TouchGFX

@A.Qasim​  - how to properly post source code:

0693W000008wfhEQAQ.png@A.Qasim​

I have tried the standard function strcat() but it doesn't allow implementation as it opposes the Unicode::UnicodeChar* getText() function.\and upon adding the two strings the decimal values get added up and output a random number i.e,

st1 = 80 //"P"
st2 = 59 //":"
 
*st3 = *st1+*st2
*st3 = 139 //null character "?"