Announcement

Collapse
No announcement yet.

Delete text inside brackets in Table

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

  • Delete text inside brackets in Table

    Hey all,

    I need to delete some "unkown" text inside some brackets which are loaded from being Text File to an Table.
    Like in the example below. But my Problem is I don't have any idea to do it or even to start. I tried do load the Text to my Table and loop the String. Find to find brackets but I I just can't get any further.


    Example Table
    Code:
    {
          "id": 123456,
          "name": "Test",
          "projects": [
          {
              "id": 4343,
              "customers_id": 666,
              "name": "testymctest",
              "number": null,
           
            },
          ]
    convert to
    Code:
    {
          "id": 123456,
          "name": "Test",
          "projects": [
           ]
    ​​​​​​​

    I would be grateful for any help or answer.
    -xtc


  • #2

    This is what I can come up with it works for me you just need to add your own square brackets at the end of Table[1] at the do stuff part
    Code:
    tbl = TextFile.ReadToString("AutoPlay\\Data\\Data.txt"); --Loading File to String local Table = {}; for delimit in string.gmatch(tbl, '([^[]+)' ) do -- Breaking down by delimiter Table[#Table + 1] = delimit; -- Taking the delimited data and putting it into a table end  -- Doing stuff with the table you want. end
    string.gmatch(tbl, '([^DELIMITER]+)' ) the word DELIMITER can be replaced with anything you want to DELIMITER with like the[. If you go back and look at my car post you can delimit line by line if you want

    Comment


    • #3
      Sorry auto crap on my phone... it's anything you want to delimit and my load CSV post on page 2

      Comment


      • #4
        Originally posted by Grimsley11 View Post
        This is what I can come up with it works for me you just need to add your own square brackets at the end of Table[1] at the do stuff part
        Code:
        tbl = TextFile.ReadToString("AutoPlay\\Data\\Data.txt"); --Loading File to String local Table = {}; for delimit in string.gmatch(tbl, '([^[]+)' ) do -- Breaking down by delimiter Table[#Table + 1] = delimit; -- Taking the delimited data and putting it into a table end -- Doing stuff with the table you want. end
        string.gmatch(tbl, '([^DELIMITER]+)' ) the word DELIMITER can be replaced with anything you want to DELIMITER with like the[. If you go back and look at my car post you can delimit line by line if you want
        Thank you very much. The Whole String.gmatch was new to me but i got it working. It also helped alot to read about patterns. Was a whole new field for me.

        Comment

        Working...
        X