• Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Social Media
    •   @Wings3dOfficial
    •   @Wings3dOfficial
    •   Wings3dOfficial
    •   Wings3dOfficial
  • Register
  • Login
  • Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Register
  • Login
Wings 3D Development Forum Wings 3D Programming v
« Previous 1 2 3 4 Next »
How to check the text assigned to a Variable

 
  • 1 Vote(s) - 5 Average
How to check the text assigned to a Variable

micheus
Offline

Forum's Admin and Support | Bug fixer
Posts: 3,681
Threads: 185
Joined: Jun 2012
#4
02-09-2013, 11:32 AM
Sorry. Blush
(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...
Quote:<upper_layer sval="w_default_Bronze_2"/>
and for w_default_Bronze_2 I need " " (no text) added to the exported .xml file.
Let see if I am right now... Smile

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,
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:

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.
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Messages In This Thread
How to check the text assigned to a Variable - by oort - 02-08-2013, 08:22 PM
RE: How to check the text assigned to a Variable - by micheus - 02-08-2013, 09:32 PM
RE: How to check the text assigned to a Variable - by oort - 02-08-2013, 10:32 PM
RE: How to check the text assigned to a Variable - by micheus - 02-09-2013, 11:32 AM
RE: How to check the text assigned to a Variable - by ggaliens - 02-10-2013, 03:08 AM
RE: How to check the text assigned to a Variable - by oort - 02-11-2013, 08:00 AM
RE: How to check the text assigned to a Variable - by micheus - 02-11-2013, 03:49 PM
RE: How to check the text assigned to a Variable - by oort - 02-11-2013, 07:49 PM
RE: How to check the text assigned to a Variable - by Whimad - 10-27-2013, 01:45 PM
RE: How to check the text assigned to a Variable - by micheus - 10-27-2013, 02:41 PM
RE: How to check the text assigned to a Variable - by superhitdeals - 04-04-2014, 12:52 PM
RE: How to check the text assigned to a Variable - by martinkay - 06-30-2014, 01:44 PM

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D - Powered by MyBB

Linear Mode
Threaded Mode