# Make a number to a string and format it so that each character is appended with a /n

##### New member
Example:
Convert a Number to String:
123 to "1" + "/n" + "2" + "/n"+"3"+"/n"

Example:
Convert a Number to String:
123 to "1" + "/n" + "2" + "/n"+"3"+"/n"
Not exactly sure what you want, but here is an addchartbubble with the 123 converted to a stacked 123.

Ruby:
``````plot Data = expaverage(close,8) crosses close;

Not exactly sure what you want, but here is an addchartbubble with the 123 converted to a stacked 123.
Here is another method that creates a label with the hopefully any 3 digit number you input.
Ruby:
``````input data = 592;
def digit1 = Round(Floor(data / 100), 0);
def digit2 = Floor((data - Round(Floor(data / 100), 0) * 100) / 10);
def digit3 = (data - Round(Floor(data / 100), 0) * 100) / 10 % 1 * 10;

Holy crap that is actually quite impressive. I guess I prematurely resigned myself to just accepting that ThinkScript has a total lack of support for strings and I never even bothered to attempt a mathematical approach like that.

Last edited:
Here is another method that creates a label with the hopefully any 3 digit number you input.
Works perfectly thanks. Is there a way to dynamically convert a double to a string and then process? For example if the close = 4268.32 then I need to know that it has 4 digits to process instead of 3. Also why is it I cannot assign string to AsText. Input string1 = AsText(....) doesn't work.

Works perfectly thanks. Is there a way to dynamically convert a double to a string and then process? For example if the close = 4268.32 then I need to know that it has 4 digits to process instead of 3. Also why is it I cannot assign string to AsText. Input string1 = AsText(....) doesn't work.
TOS's string functionality is limited.

You cannot input string1 = AsText(...). Look up that function in the education tab for a further explanation of its use.

You can input text as part of a switch/case scenario, for example, input PivotType = {Woodies, Floor, default Camarilla};.

The following code has an example of how to use an input to create text in a label.

The other example helps to determine if the input 'c' value is exactly a 4 digit number.

Ruby:
``````input x = 1;
AddLabel(1, if x == 1 then "Hello" else "Goodbye", Color.WHITE);
input c = 4268.32;
AddLabel(1, if Between(c / 1000, 1, 9) then "4 digits" else "Not 4 digits" , Color.WHITE);``````

TOS's string functionality is limited.

You cannot input string1 = AsText(...). Look up that function in the education tab for a further explanation of its use.

You can input text as part of a switch/case scenario, for example, input PivotType = {Woodies, Floor, default Camarilla};.

The following code has an example of how to use an input to create text in a label.

The other example helps to determine if the input 'c' value is exactly a 4 digit number.
Thanks a lot. Perfect example for me to extend and make it work.

TOS's string functionality is limited.

You cannot input string1 = AsText(...). Look up that function in the education tab for a further explanation of its use.

You can input text as part of a switch/case scenario, for example, input PivotType = {Woodies, Floor, default Camarilla};.

The following code has an example of how to use an input to create text in a label.

The other example helps to determine if the input 'c' value is exactly a 4 digit number.
thanks for sharing , sleepyz. i forget to use between.
here is a mod of post#6 , to allow the user to pick the quantity of digits

Ruby:
``````#
input quantity_of_digits = 4;
def powernum = (quantity_of_digits-1);
def c = close;
def p = power(10, powernum);
#AddLabel(1, if Between(c / 1000, 1, 9) then "4 digits" else "Not 4 digits" , Color.WHITE);
AddLabel(1, if Between(c / p, 1, 9) then (quantity_of_digits + " digits") else ("Not " + quantity_of_digits + " digits") , Color.WHITE);
#``````

Ruby:
``````## determine quantity of digits in price
def digits = if Between(c / 1, 1, 9) then 1
else if Between(c / 10, 1, 9) then 2
else if Between(c / 100, 1, 9) then 3
else if Between(c / 1000, 1, 9) then 4
else if Between(c / 10000, 1, 9) then 5
else 0;
addlabel(1, "digits in price " + digits, color.yellow);``````

Last edited:
Hi, I am wondering if anyone could provide guidance on how to reference a section of values within a string value.
For example:
input numstring = 529755297652977529785297952980
def level_1 = first five characters in string (52975) (1st-5th character)
def level_2 = next five characters in string (52976) (6th-10th character)
def level_3 = next five characters in string (52977) 11th-15th character)
etc......

I can make this function work in excel using the =MID variable. I was just hoping there was a way to do this in Thinkscript as well.

Thanks

87k+ Posts
263 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?