473,320 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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....
Sep 19 '08 #1
4 3870
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
_____
http://www.guffa.com
Sep 19 '08 #2
OD
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___
www.e-naxos.com
Sep 22 '08 #3
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
Sep 22 '08 #4
OD
>
>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___
www.e-naxos.com
Sep 24 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ET | last post by:
I don't know whats the problem, but after I added functions to first verify, then relink linked tables if not found, now I can't convert that database to MDE format. I can split the database, but...
15
by: Yifan | last post by:
Hi Does anybody know how to convert System::String* to char*? I searched the System::String class members and did not find any. Thanks Yifan
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
6
by: compboy | last post by:
Can anyone help me about this. I have been trying all the ways I knew and I could find but just didnt work. I have tried: using itoa but it says that it doesnt have that function. and...
42
by: =?Utf-8?B?UGxheWE=?= | last post by:
I have an if statement that isn't working correctly and I was wondering how I check for a blank string. My Code Example if me.fieldname(arrayIndex) = "" then ----- end if When I do this and...
3
by: =?utf-8?B?Qm9yaXMgRHXFoWVr?= | last post by:
Hi, I am looking for the best way to convert a string of length 1 (= 1 character as string) to integer that has the same value as numeric representation of that character. Background: I am...
8
by: te509 | last post by:
Hi guys, does anybody know how to convert a long sequence of bits to a bit-string? I want to avoid this: '949456129574336313917039111707606368434510426593532217946399871489' I would...
2
by: Vamp4L | last post by:
Hello, Specifically, I'm trying to convert the Internet Explorer history file (index.dat) into a readable format. Anyone done something similar or know of any functions that may help with such a...
4
by: Danny Shevitz | last post by:
Simple question here: I have a multiline string representing the body of a function. I have control over the string, so I can use either of the following: str = ''' print state return True...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.