简体   繁体   English

如何将字符串转换为整数表示形式并将其更改回

[英]how to convert a string into integer representation and change it back

I was wondering if there were any good methods to change a string into an integer representation and then be able to change the integer representation back to a string? 我想知道是否有什么好的方法可以将字符串更改为整数表示形式,然后将整数表示形式更改回字符串? There are a lot of ways to change a string to an integer representation by changing each character to ASCII, etc. but I was confused by how to change the ascii integer back into the fully formed string. 有很多方法可以通过将每个字符更改为ASCII等将字符串更改为整数表示形式,但是我对如何将ascii整数改回完整的字符串感到困惑。

I am trying to represent my object of 3 strings into an integer so that I do not have to group by 3 string but just 1 integer. 我试图将3个字符串的对象表示为一个整数,这样我就不必将3个字符串分组,而只需将1个整数分组即可。

For example an object of : 例如一个对象:

("hey", "hello", "goodbye") (“嘿”,“你好”,“再见”)

would have an int representation of lets say 123423425 with some algorithm. 用某种算法可以让我们说123423425的int表示。

Then if possible I would like to be able convert that int from another algorithm back into 然后,如果可能的话,我希望能够将该int从其他算法转换回

("hey", "hello", "goodbye") (“嘿”,“你好”,“再见”)

Any help would be appreciated 任何帮助,将不胜感激

int number = Int32.Parse("45");
string formatted = number.ToString()//add formatting if needed

You can go back and forth 你可以来回走

Reference for format strings: http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx 格式字符串的参考: http : //msdn.microsoft.com/zh-cn/library/dwhawy9k( v= vs.110).aspx

Convert char array to string 将char数组转换为字符串

char[] charArray = {'1', '2', '3'};
String str = String.valueOf(charArray);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM