aspose file tools*
The moose likes Beginning Java and the fly likes How to convert a string to integer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to convert a string to integer" Watch "How to convert a string to integer" New topic
Author

How to convert a string to integer

Arun R. S. Chandran
Ranch Hand

Joined: Oct 08, 2008
Posts: 81
Hi friends,

I wish to convert a strig to an integer and viceversa.

For Eg: A pure string "ARUN"- I wish to convert this to an integer.
And by converting that integer to string , I wish to get the same string
"ARUN"

Can anybody give me a proper solution for this?

Please help me if it is possible, because I am stuck in a project by this problem....

-ARUN
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
I guess it depends on what you mean by "integer". An int, in Java, has a maximum possible value. That means there's a finite number of values that can possibly be represented. Same for a long. How many possible different Strings are there? Unless you limit the length of the possible Strings, I think there is an infinite number. So an int or long cannot possibly represent all possible values. But there may be other data types that can (hint: check the java.math package in the API).

I would say that any possible String can be converted into a series of bytes. And any possible series of bytes can be converted into an integer (but not necessarily an int or long) - as long as you've got enough memory. Think about how you might do this.
Arun R. S. Chandran
Ranch Hand

Joined: Oct 08, 2008
Posts: 81
Dear friend..

The string length is limited, we created in such a way. Because these are already existing shop names. These are fixed.
Now can you please help me how can I convert this one?

-ARUN
kranthi chamarthi
Ranch Hand

Joined: May 08, 2007
Posts: 95
Why do you want to do this conversion? Is it for some kind of security purpose? If that is the case then you can search for sncryption algorithms in google.
For example a simple encryption algorithm is Substitution. If you use this for string "abc" you will get "123" (1-a,2-b,3-c). Hope this may be useful
Arun R. S. Chandran
Ranch Hand

Joined: Oct 08, 2008
Posts: 81
thank you for your reply,

But it's not security purpose. It's for sending data to a RTP. So RTP cant understand the string data. So I have to convert it to int. And when RTP sending some data in integer format I have to convert this to string for Display purpose.
That's the problem I am facing here..

-ARUN
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to convert a string to integer