String splitting to create multiple variables

Hello again,

I am trying to split a list of strings into multiple variables. Here is my situation below:

Here you can only see the long id of each document but the format of the two strings are like this: ID, 20, 2

The 20 and 2 are prices and quantity pulled from an API.

Can split all these strings into 3 sub strings for each and use in other modules?

Thank you very much,
Robin

Hey @Robin_Sola

Can I get screenshot of full output strings

2 Likes

Sure thing here it is. Thanks! @Abhishek

@Robin_Sola

I need full value to solve this problem

And you can simply use split function of make

Split(string ; ,)

2 Likes

Oh sorry :slight_smile:

Hope this helps.

@Robin_Sola
Try this

the result
Screenshot 2024-02-07 225615

2 Likes

thank @Abhishek

I seem to have any issue doing with all the item in the array.

As you can see I can only split the first row of the array.

Thanks again for the help

@Robin_Sola

You can use iterator for this problem

2 Likes

Welcome to the Make community!

Please avoid screenshotting output bundles! We cannot expand collapsed properties, and cannot copy text from screenshots!

Please provide the output bundles of that modules by running the scenario, then click the white speech bubble on the top-right of each module and select “Download output bundles”.
Screenshot_2023-10-06_141025

You can paste the formatted output bundle in this manner:

  • Either add three backticks ``` before and after the code, like this:

    ```
    input/output bundle content goes here
    ```

  • Or use the format code button in the editor:
    Screenshot_2023-10-02_191027

Providing the output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.

This will allow others to better assist you. Thanks!

2 Likes

Hi @samliew , thanks a lot for this information. I am new to Make and I really appreciate all the guidance!

Here is the data that I am trying to manipulate, the “productList” data is an array in the array format “String, Number, Number” I would like to split all the rows of this array. Thanks again!

[
    {
        "currency": "GBP",
        "customerID": "0",
        "vendorName": "Sorakami",
        "billingCity": "London",
        "productList": [
            "w_junmai_akita_sake_komachi_muroka_genshu_watanabe_shuzo_gifu,1,10",
            "14_junmai_ginjo_oh-karakuchi_(super_dry)_yamada_nishiki_miinokotobuki_fukuoka,1,25"
        ],
        "billingPhone": "",
        "billingState": "Nova Scotia",
        "orderedTotal": "41.9",
        "shippingCity": "London",
        "shippingRate": "6.9",
        "totalCartTax": "null",
        "vendorPayout": "38.05",
        "customerEmail": "r",
        "shippingPhone": "6",
        "shippingState": "Nova Scotia",
        "vendorTaxRate": "0.2",
        "billingCompany": null,
        "billingCountry": "Canada",
        "billingLastName": "",
        "billingPostCode": "",
        "shippingCompany": null,
        "shippingCountry": "Canada",
        "billingAddress01": "",
        "billingAddress02": null,
        "billingFirstName": "Robin",
        "shippingLastName": "",
        "shippingPostCode": "",
        "shippingAddress01": "",
        "shippingAddress02": null,
        "shippingFirstName": "Robin",
        "whatsakeCommission": "3.85",
        "uniqueCartItemNumber": "2"
    }
]

Welcome to the Make community!

You can do it in a single operation using a Text Parser “Match Pattern” module with this regular expression pattern

\s*(?<id>[^,]+),(?<price>\d+),(?<qty>\d+)

Regex test: https://regex101.com/r/w4fnvR

Important Info

  • :warning: Global match must be set to YES!

  • You need to join your array using the {{newline}} variable (see below screenshot)

Screenshot

Output

Screenshot_2024-02-08_160223

Import this module into your scenario

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV to paste in the canvas.

  3. Click on each imported module and save it. You may need to remap some variables.

Modules JSON Export

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 71,
                    "module": "regexp:Parser",
                    "version": 1,
                    "parameters": {
                        "pattern": "\\s*(?<id>[^,]+),(?<price>\\d+),(?<qty>\\d+)",
                        "global": true,
                        "sensitive": true,
                        "multiline": false,
                        "singleline": false,
                        "continueWhenNoRes": false,
                        "ignoreInfiniteLoopsWhenGlobal": false
                    },
                    "mapper": {
                        "text": "{{join(69.productList; newline)}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 84,
                            "y": -1927,
                            "messages": [
                                {
                                    "category": "last",
                                    "severity": "warning",
                                    "message": "A transformer should not be the last module in the route."
                                }
                            ]
                        },
                        "restore": {},
                        "parameters": [
                            {
                                "name": "pattern",
                                "type": "text",
                                "label": "Pattern",
                                "required": true
                            },
                            {
                                "name": "global",
                                "type": "boolean",
                                "label": "Global match",
                                "required": true
                            },
                            {
                                "name": "sensitive",
                                "type": "boolean",
                                "label": "Case sensitive",
                                "required": true
                            },
                            {
                                "name": "multiline",
                                "type": "boolean",
                                "label": "Multiline",
                                "required": true
                            },
                            {
                                "name": "singleline",
                                "type": "boolean",
                                "label": "Singleline",
                                "required": true
                            },
                            {
                                "name": "continueWhenNoRes",
                                "type": "boolean",
                                "label": "Continue the execution of the route even if the module finds no matches",
                                "required": true
                            },
                            {
                                "name": "ignoreInfiniteLoopsWhenGlobal",
                                "type": "boolean",
                                "label": "Ignore errors when there is an infinite search loop",
                                "required": true
                            }
                        ],
                        "expect": [
                            {
                                "name": "text",
                                "type": "text",
                                "label": "Text"
                            }
                        ],
                        "interface": [
                            {
                                "type": "text",
                                "name": "id",
                                "label": "id"
                            },
                            {
                                "type": "text",
                                "name": "price",
                                "label": "price"
                            },
                            {
                                "type": "text",
                                "name": "qty",
                                "label": "qty"
                            },
                            {
                                "type": "uinteger",
                                "name": "i",
                                "label": "i"
                            },
                            {
                                "type": "any",
                                "name": "__IMTMATCH__",
                                "label": "Fallback Match"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

For more information, see Text Parser in the Make Help Center:

Match Pattern
The Match pattern module enables you to find and extract string elements matching a search pattern from a given text. The search pattern is a regular expression (aka regex or regexp), which is a sequence of characters in which each character is either a metacharacter, having a special meaning, or a regular character that has a literal meaning.

Hope this helps!

2 Likes

Thank you @samliew I used the text parser and I do get the same result below with two different bundles.

[
    {
        "i": 1,
        "id": "w_junmai_akita_sake_komachi_muroka_genshu_watanabe_shuzo_gifu",
        "qty": "1",
        "price": "10"
    },
    {
        "i": 2,
        "id": "14_junmai_ginjo_oh-karakuchi_(super_dry)_yamada_nishiki_miinokotobuki_fukuoka",
        "qty": "1",
        "price": "25"
    }
]```


However I am now wondering how to get each of these variables to use in mapping for other modules. Is the get function?

Thank you again for all the help!

You can use an iterator, or map+get functions.

For more information, see

Links

Here are some useful links and guides you can use to learn more on how to use the Make platform, apps, and app modules. I found these useful when I was learning Make, and hope they might benefit you too —

General

Help Center Basics

Articles & Videos

3 Likes

Thank you again for all the help you are a real Champ!

3 Likes