Forum Discussion

bklabel1's avatar
bklabel1
Occasional Contributor
4 years ago

Formatting data in a request

My phone number is coming from an expanded expression in the format of 333-333-1234.  I want to change it to (333)-333-1234 before using it in the POST.   I'm looking in documentation but I do not ...
  • HimanshuTayal's avatar
    4 years ago

    bklabel1 : There is no straight way to do this, you can achieve this by writing your groovy code.

     

    You can use below code if input format will be as mentioned in question

     

    def r = '333-333-1234'
    
    def with_braces =  '(' + r.split('-')[0] + ')'
    
    desired_num = with_braces +'-'+ r.split('-')[1] +'-'+ r.split('-')[2]
    
    log.info desired_num