Get string from resources using name

Former Member
Former Member
How can I get a string from resources using a string? :)

Example, that not works:
<string id="test">1</string>
var name = "test";
Rez.Strings.name;

I know Rez.Strings.test works, but I have many strings and dont wont to create an array like [Rez.Strings.test, Rez.Strings.test2, Rez.Strings.test3] etc.

Thx for help :)
  • The id of the string is "test" and not "name".... I don't think you can use a string as part of a Rez call parameter, as the paramerter "I think" is done at compile time...

    Do you really need to load all the strings at once and why as an array?
  • Former Member
    Former Member over 9 years ago
    Do you really need to load all the strings at once and why as an array?


    I dont need to load all at once, but I need to select from x strings. So with array I can like get value x like Ui.loadResource(array[x]) :)

    Hmm.. but do you know how the hashCode is calculated? Or is it just random? :D

    Thx!!
  • Maybe someone that knows how the compiler works can tell you about the hash codes. I don't know

    But what if you load your stings using the actual ids and then build your own array?

    array[0]=Ui.loadResource(Rez.Strings.strA);

    array[1]=Ui.loadResource(Rez.Strings.strB);

    etc?

    Then just use array[x] for the string you want.
  • Former Member
    Former Member over 9 years ago
    Good idea! I think I will do it that way :)
    Thx for help
  • Former Member
    Former Member over 7 years ago
    Hi, i'm gonna re-open this subject because i got the same problem.

    I've got 30 strings and i would like to display only one. I could load all the string in a array but it will take a lot a space for nothing.

    So if someone know how open strings like BrownieCake think by using Ui.loadResource(Rez.Strings."myId"), or if it's just impossible ?

    Thanks by advance.
  • Former Member
    Former Member over 7 years ago
    I don't think I understand what you are trying to do here. Rez.Strings is an object, so you can access its members in one of two ways:

    Rez.Strings.symbol or Rez.Strings[:symbol]

    These values are only id values and won't take up very much space until they are passed to WatchUi.loadResource and the string is loaded.
  • Former Member
    Former Member over 7 years ago
    I think - I know what is the problem - as I have/had similar one and no good (from memory perspective) solution.

    Imagine that want to show bitmap for weather conditions. Ideal solution would be - I'm storing weather code as number (1,2,3...) representing bitmaps.

    Ideal (not possible?) solution would be:

    var rezName = "weather" + weatherCode.toString();
    Rez.Strings.byName(rezName); // or something with similar functionality

    Instead I'm having:

    if( weatherCode==1) {
    icon = :weather1;
    } else if (weatherCode == 2) {
    icon = :weather2;

    // switch is more memory consuming anyway so I'm using if - else construction
  • Former Member
    Former Member over 7 years ago
    It is not possible to convert from a string to a symbol in this way. These mappings are defined at compile time.

    You should probably use a lookup table. I would expect this to take less app space than an if/else.

    icons = [:weather1,:weather2,...]; //Do this in an initialization routine so it is only constructed once.

    icon = icons[weatherCode];
  • Former Member
    Former Member over 7 years ago
    Ok, so it's not possible.

    Thanks for your answers.
  • I'm trying to do the same with Rez.Styles, but it doesn't work:

    Rez.Strings[:AppName] works

    but:

    Rez.Styles[:system_loc__hint_button_left_middle].x
    doesn't, even though Rez.Styles.system_loc__hint_button_left_middle.x exists.