Languages

Menu
Sites
Language
String building tip on the native application development

String building tip on the native application development

1. Scenario description

In many cases, developer need to build a string dynamically, such as, construct an image/icon full path, concatenate two sub-strings (str1 + str2), replace a sub-string, etc. In c language, it’s not as convenient as in those advantage languages (Java, C#, Python).

2. Solution

In traditional way, developer will use the standard c char manipulate functions (string.h, stdio.h).

Example:

char filename[PATH_MAX];    
snprintf(filename, sizeof(filename), "%s%s", ICON_DIR, “icon_name.png”);

 

In Tizen, developer can use another more powerful string API, the eina_strbuf.h.

Eina_Strbuf *strbuf = eina_strbuf_new();

eina_strbuf_append_printf(strbuf, "%s%s", str1, str2);

char *txt = eina_strbuf_string_steal(strbuf);

eina_strbuf_free(strbuf);

// txt manipulate goes here

free(txt); // remember to free the string after it isn’t needed anymore.

 

Developer can find more details about this API from header file and function description document in Tizen DEVELOPERS site (https://developer.tizen.org/documentation/guides/native-application/ui/eina/data-types)

 

Hope this tip give help for your task...Good luck!

Responses

1 Replies
colin Rao

Ustring in #include <utils_i18n.h>

you can get help from the IDE help doc.