java - Using a variable in getString() -


i'm using random number pull string resource xml, of have similar beginning (they named "quote" number after, quote1, quote2, etc.

i'm trying find way access them using getresources().getstring() don't know how pass that, since getstring wants int, can't

string quotetoget="r.string.quote"+string.valueof(randnum)  //randnum random int generated 

because quotetoget string, getstring(quotetoget) doesn't work.

what else achieve this?

with method, should resource name.

private string getresstringid(string astring) {       string packagename = getpackagename();       int resid = getresources().getidentifier(astring, "string", packagename);       return getstring(resid);     } 

use following:

string quotetoget= getresstringid("quote"+string.valueof(randnum)); 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -