string formatting in FS?

adamohern
adamohern Member, OS Professional Posts: 216 PRO
edited April 2016 in FeatureScript
I'm used to Python's string formatting, where I can insert variables into a longer string and the result is concatenated automatically. Is there anything similar in FS? In the example below, look how much more readable the Python example is.

Python:

"Hello, my name is %s and I like to eat %s on %s." % (name, food, day_of_week)
or

"Hello, my name is {} and I like to eat {} on {}.".format(name, food, day_of_week)
vs FeatureScript (AFAIK):

"Hello, my name is " ~ name ~ " and I like to eat " ~ food ~ " on " ~ day_of_week ~ "."

Comments

  • kevin_o_toole_1
    kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565 image
    edited April 2016
    There isn't right now. I suspect at some point the FS solution for this will look a lot like sprintf in C... something like:
    format("%d plus %d is %d", a, b, a+b);
    
    This is NOT available today – your quotes and twiddles solution is currently the only way to go.
  • florian_neurohr
    florian_neurohr Member Posts: 8 EDU

    Any updates on that issue?

  • MichaelPascoe
    MichaelPascoe Member Posts: 2,965 PRO

    @florian_neurohr not that I'm aware of. You still have to use ~ to join strings. There are some useful new regex() functions though.


    RENDERCAD - Photorealistic product rendering.
    CADSharp - Professional CAD + software consulting.

    ▚▞▚▞▚▞▚▞▚
  • _anton
    _anton Member, Onshape Employees Posts: 555 image

    If you just wanted to join an array of strings with a delimiter, there's a join function. Otherwise, yeah, no out-of-the-box solution.