It's impossible. Suppose your int argument is 32 bits. The text string will be made of ' ' , a-zA-Z and 0-9 and half a dozen punctuation marks, for a total of about 1 + 2 * 26 + 10 + 6 = 69 characters. For strings of 6 characters, you already have more possible strings than integer values (log (2 ^ 32) / log (69) = 5.23). Use a long long of 64 bits and you are done with 11 characters.
As the other answers say, you can use a hash function (there are a lot of floats around it) that will display strings in integers and (hopefully) distribute them equally across the selected range of integers.
There are methods for constructing perfect hash functions that, for a fixed set of lines, generate a function and a range that is not too large, which does not guarantee collisions (no two lines give a single whole).
If this is used in the program, and the lines can be controlled by an attacker, you are subjected to attacks of algorithmic complexity (an attacker can flood you with lines that collide).
source share