2 ways to do that, depending on your need.
If your spritefont is monospaced, it's much easier. The "textWidth" function should return len(Function.Param(0)) * (characterWidth + characterSpacing).
However, if some characters have different width, you'll have to use the SpriteFont.TextWidth expression. You can either use a dedicated SpriteFont to "measure" text, or create a temporary one to do it.
Here's an edited version using a SpriteFont.