Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Converting an integer into a string

MadPandaMadPanda Posts: 4Member
i want to convert an integer to a string in turbo pascal, why will these lines of code cause an error, strings can hold numbers cant they?
or am i looking at it from thew wrong angle

I : integer;
S : String;

I:=S

any help would be appriciated from a clueles begginer

Comments

  • zibadianzibadian Posts: 6,349Member
    : i want to convert an integer to a string in turbo pascal, why will these lines of code cause an error, strings can hold numbers cant they?
    : or am i looking at it from thew wrong angle
    :
    : I : integer;
    : S : String;
    :
    : I:=S
    :
    : any help would be appriciated from a clueles begginer
    :
    Use the Str() function.
  • richard_wise25richard_wise25 Posts: 52Member
    var
    i: integer;
    s: string;
    begin
    str(i, s);
    write(i);
  • viv.viv. Posts: 72Member
    you can't store a integer variable into a string var.

    note that you can store an integer value in a real var. etc

  • zibadianzibadian Posts: 6,349Member
    : you can't store a integer variable into a string var.
    :
    : note that you can store an integer value in a real var. etc
    :
    :
    You can store an integer in a string, but when you want to perform a calculation with that integer, you need to convert it to an integer. It is possible to store any variable in any other variable, as long as you define the rules to convert the two.
  • viv.viv. Posts: 72Member
    : : you can't store a integer variable into a string var.
    : :
    : : note that you can store an integer value in a real var. etc
    : :
    : :
    : You can store an integer in a string, but when you want to perform a calculation with that integer, you need to convert it to an integer. It is possible to store any variable in any other variable, as long as you define the rules to convert the two.
    :

    i tried, it doesnt work , the compiler will tell you type mismatch.


  • zibadianzibadian Posts: 6,349Member
    : : : you can't store a integer variable into a string var.
    : : :
    : : : note that you can store an integer value in a real var. etc
    : : :
    : : :
    : : You can store an integer in a string, but when you want to perform a calculation with that integer, you need to convert it to an integer. It is possible to store any variable in any other variable, as long as you define the rules to convert the two.
    : :
    :
    : i tried, it doesnt work , the compiler will tell you type mismatch.
    :
    You need to convert it using Str() or Val(). You cannot directly assign it.

Sign In or Register to comment.