java - i have four string values from method. how to combine strings? -
so value of these string method, , need combine them file address, can't combine string did on file_path_string. tried use concat method, doesn't work too. file_path_string equal first string ,which world_path in case
public static final string world_path = "the world/"; public static string continents_name=""; public static string country_name=""; public static string file_type=""; public static string file_path_string = world_path + continents_name + country_name + file_type; public static file file_path = new file(file_path_string);
it should work like, when click on map, method return name of region me,and wills store them in static string. tried debug. of strings have value , correct. file_path_string equal first string put in there. after run program, continents_name = asia country_name should equal continents_name because that's how set file address file_path = .png method load map
i curious, how "have 4 string values method" - can enlighten on that? because if this:
getstrings(world_path, continents_name, country_name, file_type);
then that's problem - function getstrings()
can't modify strings passed in.
i making wild guesses of course, since haven't given enough information.
can like:
string path = getworldpath() + getcontinent() + getcountry() + getfiletype();
that is, implement 4 separate methods 4 separate parts of path?
otherwise have define type can return 4 strings @ same time, or return them in container array:
void test() { string[] pathparts = getstrings(); file_path_string = pathparts[0] + pathparts[1] + pathparts[2] + pathparts[3]; } string[] getstrings() { string[] ret = new string[4]; ret[0] = "the world"; ret[1] = "south america"; ret[2] = "chile"; ret[3] = ".txt"; return ret; }
of course, if going concatenate strings, in getstrings()
function.
Comments
Post a Comment