02-09-2013, 11:32 AM
Sorry.
All these samples are considering a fixed value for the Texname's sufix - equal "1".
In case you can have other declarations it would be better try to create something more generic. By using the last example, we could create a function and use it like follow:
(02-08-2013, 10:32 PM)oort Wrote: For w_default_Bronze_1 I need to get the following text added to the exported .xml file...Let see if I am right now...
Quote:<upper_layer sval="w_default_Bronze_2"/>and for w_default_Bronze_2 I need " " (no text) added to the exported .xml file.
Code:
...
Tokens=string:tokens(Texname,"_"),
Num=lists:last(Tokens),
UpperLayer = case list_to_integer(Num) of
1 -> string:join(lists:subtract(Tokens, [Num]),"_") ++"_2";
_ -> ""
end,
Code:
...
Tokens=string:tokens(Texname,"_"),
Num=lists:last(Tokens),
UpperLayer = case list_to_integer(Num) of
1 -> lists:sublist(Texname, length(Texname)-length(Num)) ++"2";
_ -> ""
end,
Code:
...
Idx=string:rchr(Texname,$_),
Num=string:sub_string(Texname,Idx+1),
UpperLayer = case string:to_integer(Num) of
{1, _} -> string:sub_string(Texname, 1, length(Texname)-length(Num)) ++"2";
_ -> ""
end,
In case you can have other declarations it would be better try to create something more generic. By using the last example, we could create a function and use it like follow:
Code:
...
% if at this point Texname="w_default_Bronze_1" we'll get "w_default_Bronze_2"
UpperLayer = get_up_level(Texname),
...
% if at this point Texname="w_default_Bronze_5" we'll get "w_default_Bronze_6"
UpperLayer = get_up_level(Texname),
...
------------
get_up_level(Texname) ->
Idx=string:rchr(Texname,$_),
Num=string:sub_string(Texname,Idx+1),
case string:to_integer(Num) of
{N, _} when is_integer(N) -> string:sub_string(Texname, 1, length(Texname)-length(Num)) ++integer_to_list(N+1);
_ -> ""
end.