Author Topic: Convert Number to String  (Read 4986 times)

0 Members and 1 Guest are viewing this topic.

Offline Derbles

  • LV0 Newcomer (Next: 5)
  • Posts: 1
  • Rating: +0/-0
    • View Profile
Convert Number to String
« on: November 23, 2017, 02:52:09 am »
Hey Everyone,

Is it possible to convert a number into a string?

For example, I have the String: "You found # $s"

Now I'm trying to replace the # with a number and replace the $ with a string.

It's trivial to replace the $, but I'm having trouble a number such as 25 into a string (list of chars).

Any thoughts?

Thanks!

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Convert Number to String
« Reply #1 on: November 25, 2017, 08:48:48 am »
Axe has you covered!

You can do something like

Code: [Select]
:Text "You found # "
:Text 25>Dec

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline E37

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +23/-0
  • Trial and error is the best teacher
    • View Profile
Re: Convert Number to String
« Reply #2 on: November 25, 2017, 03:34:15 pm »
If you need the number as a string you can:
Code: [Select]
:ClrHome
:Disp NUMBER >Dec
:Copy(L5, L1, 5)
:ClrHome
:0 -> {L1 + 5}
That will save the number as a string in L1. It doesn't have to be L1 it can be any string. If the number is less than 5 digits long the string will start with space. So if the number was 354 the string would be "  354". Notice that the string has 2 spaces before the number.

The copy function can be used to take a "screenshot" of the homescreen. Copy(L5, POINTER, AMOUNT) would copy the AMOUNT of characters from the homescreen to POINTER. All the code does is display the number and copies the first 5 characters of the homescreen which happens to be the number that was displayed.
I'm still around... kind of.