convert an int to a string without built in functions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sagar

    convert an int to a string without built in functions

    Hi Guys..
    I Wanted to convert an int to a string in C#...but i cannot use any
    built in functions.So, can any one tell me an algorithm or a program
    to do so....please is urgent....
  • =?ISO-8859-1?Q?G=F6ran_Andersson?=

    #2
    Re: convert an int to a string without built in functions

    sagar wrote:
    Hi Guys..
    I Wanted to convert an int to a string in C#...but i cannot use any
    built in functions.So, can any one tell me an algorithm or a program
    to do so....please is urgent....
    When asking a question like this, you should explain up front that it is
    a homework assignment, so that anyone replying to it can assist you at
    an appropriate level.

    Strictly speaking what you are asking for is not possible. You have to
    use some built in functions to create any string at all. I assume that
    you at least may use the functions for converting a character into a
    string and concatenating strings, or creating a string from an array of
    characters.

    As the point of the excercise is to do what the ToString method does, I
    assume that you may not use that method at all. Therefore you will have
    to convert a value between 0 to 9 into a character by creating the
    character value from the character code. The character code for the
    digit 0 is 48, so you just add 48 to the value and cast it to a char.

    To get the values for the separate digits, you use the modulo operator
    (%) and the division operator (/).

    You can either convert each character to a string and concatenate the
    strings, or put the characters in a character array (char[]) and create
    a string from the array.

    --
    Göran Andersson
    _____
    Göran Anderssons privata hemsida.

    Comment

    • OD

      #3
      Re: convert an int to a string without built in functions

      sagar wrote:
      >Hi Guys..
      >I Wanted to convert an int to a string in C#...but i cannot use any
      >built in functions.So, can any one tell me an algorithm or a program
      >to do so....please is urgent....
      >
      When asking a question like this, you should explain up front that it is a
      homework assignment, so that anyone replying to it can assist you at an
      appropriate level.
      >
      Strictly speaking what you are asking for is not possible. You have to use
      some built in functions to create any string at all. I assume that you at
      least may use the functions for converting a character into a string and
      concatenating strings, or creating a string from an array of characters.
      >
      As the point of the excercise is to do what the ToString method does, I
      assume that you may not use that method at all. Therefore you will have to
      convert a value between 0 to 9 into a character by creating the character
      value from the character code. The character code for the digit 0 is 48, so
      you just add 48 to the value and cast it to a char.
      >
      To get the values for the separate digits, you use the modulo operator (%)
      and the division operator (/).
      >
      You can either convert each character to a string and concatenate the
      strings, or put the characters in a character array (char[]) and create a
      string from the array.
      you forgot another solution : writing a web service that makes the call
      the Tostring and call this service from the application, so the latter
      can convert an integer to a string not using any build-in function !
      (anyone has something more crazy ? :-) )

      --


      OD___



      Comment

      • Chris Dunaway

        #4
        Re: convert an int to a string without built in functions

        On Sep 22, 8:47 am, OD <webmaster @ e-naxos dot comwrote:
        can convert an integer to a string not using any build-in function !
        (anyone has something more crazy ? :-) )
        I would say create a database table with 2 columns, the first an
        integer column and the second the string representation. Then
        populate the table with every possible integer. Then use ADO to
        lookup the correct string based on the integer passed in!! :p

        :)

        Chris

        Comment

        • OD

          #5
          Re: convert an int to a string without built in functions

          >
          >can convert an integer to a string not using any build-in function !
          >(anyone has something more crazy ? :-) )
          >
          I would say create a database table with 2 columns, the first an
          integer column and the second the string representation. Then
          populate the table with every possible integer. Then use ADO to
          lookup the correct string based on the integer passed in!! :p
          >
          you win, it's totaly crazy :-)

          --


          OD___



          Comment

          Working...