Announcement

Collapse
No announcement yet.

Devide 2 words and get First letter of each word HELP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Devide 2 words and get First letter of each word HELP

    Hello i having trouble with this small scripting ideas, i know this is so just noob for you but for me really need help.


    I have 1 input user can type two or even three item on it..
    example: Toyota Honda


    then i have a button to separate those two words and get only the first letter so the output will be T H,
    but in the case the user make a space before Toyota my output will get a space and H..

    can anyone help me with this with a simple example? thanks

  • #2
    Hi @telco,
    but in the case the user make a space before Toyota my output will get a space
    Try this

    Code:
    --Stop spaces in input box
    --The number '32' equals the ASCII Decimal SPACE
    if e_Key == 32 then
        strInput1 = Input.GetText("Input1")
            strInput1 = String.Replace(strInput1, " ", "", false)
                strInput1Length = String.Length(strInput1)
                    Input.SetText("Input1", strInput1)
                        Input.SetSelection("Input1", strInput1Length+1, strInput1Length+1)
    end
    Cheers

    Comment


    • #3
      hello colc, actually i need the space, because if user enter two words it needs space.. my concern if the user enter space before the first word. then after that if the two words have no space before the first word i need to devide the words and get the first Character of each word.




      Comment


      • #4
        Code:
        function string:split(sep)
           local sep, fields = sep or ":", {};
           local pattern = string.format("([^%s]+)", sep);
           self:gsub(pattern, function(c) fields[#fields+1] = c; end);
           return fields;
        end
        
        function short(s)
            local entries = s:split(" ");
        
            for index, entry in pairs(entries) do
                entries[index] = entry:sub(1, 1);
            end
        
            return table.concat(entries, " ");
        end
        
        Dialog.Message("Toyota Honda Mazda", short("Toyota Honda Mazda"));
        Something like that?
        Bas Groothedde
        Imagine Programming :: Blog

        AMS8 Plugins
        IMXLH Compiler

        Comment


        • #5
          Hello Imagine Programming i will check if this one will work... thanks

          Comment


          • #6
            Here's another one, using a single function.

            Code:
            local assert, type, insert, concat = assert, type, table.insert, table.concat;
            
            function short(s)
                assert(type(s) == "string", "argument #1 must be of type string");
                
                local result = {};
                for v in (" "..s):gmatch("%s([%w%W])") do
                    insert(result, v);
                end
                return concat(result, " ");
            end
            Bas Groothedde
            Imagine Programming :: Blog

            AMS8 Plugins
            IMXLH Compiler

            Comment


            • #7
              Hello IP here is the example i made that i want to achieve.. thank you
              Attached Files

              Comment


              • #8
                Hi Telco,

                I'm currently not on a Windows machine and I don't feel like firing it up, can't you implement the function I shared? Place it in globals, call it with the user input and its result will be the format you were looking for - I believe.
                Bas Groothedde
                Imagine Programming :: Blog

                AMS8 Plugins
                IMXLH Compiler

                Comment


                • #9
                  hey @telco,
                  MAN you should really being trying this stuff instead of getting everyone to do your WORK, your example had NO code
                  It looks like you never tried IP's help

                  I have quickly put this together for you using the codes supplied from Imagine Programming and colc

                  telco_fixed.apz
                  PLEASE study and LEARN

                  Comment


                  • #10
                    +1 - thanks charliechaps
                    Bas Groothedde
                    Imagine Programming :: Blog

                    AMS8 Plugins
                    IMXLH Compiler

                    Comment


                    • #11
                      final reworked



                      Code:
                      [ATTACH]n303927[/ATTACH]

                      Comment


                      • #12
                        Hello everyone.. sorry for the late response just got home for a vacation.. yeah i ddint try the IP share because i dont know where to put it..
                        charliechaps and herrin and Imagine Programming thank you for contributions.

                        Comment


                        • #13
                          Hello i just tried it and it works for my needs.. thank you so much everyone even though i dont understand the code in global,.

                          telco

                          Comment


                          • #14
                            Originally posted by telco View Post
                            ... yeah i ddint try the IP share because i dont know where to put it...
                            Trying is the most important part of software development, you could've put my first example pretty much anywhere.
                            Bas Groothedde
                            Imagine Programming :: Blog

                            AMS8 Plugins
                            IMXLH Compiler

                            Comment


                            • #15
                              Imagine Programming thank you so much...

                              Comment

                              Working...
                              X