Skip to main content
Question

How to sort out string variable

  • November 17, 2023
  • 1 reply
  • 111 views

Forum|alt.badge.img+4

I want to create a small bot to sort out string variables that contain numbers in it. Please, can you point out how to make this bot work? 

Thanks

1 reply

Abhay Naik
Forum|alt.badge.img+7
  • Navigator | Tier 3
  • 98 replies
  • November 17, 2023

Hi @jsegura 2409 ,

You can use below python code and use it into python commands. Function will be “sort_numbers_in_string” input you can pass the string variable which needs to be sorted and output need to be a string variable which gives out the output.

Remember this would require python installation on the machine where the bot will be running.

import re

def sort_numbers_in_string(input_string):
    # Find all numbers in the input string using regular expression
    numbers_list = re.findall(r'\d+', input_string)

    # Convert the matched numbers from strings to integers and sort them
    sorted_numbers = sorted(map(int, numbers_list))

    return sorted_numbers


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings