简体   繁体   English

编解码字符串

[英]Encoding-Decoding string

Is there a way in Android/Java which encode the string in below-mentioned way: Android / Java中是否有一种以下述方式对字符串进行编码的方式:

Original String: "Today is a sunny day. I must go out."

apply encoding now 立即套用编码

Resulting string after encoding: "Today is a sunny day."

Now decode the encoded string to get the original string: 现在解码编码的字符串以获取原始字符串:

Original String: "Today is a sunny day. I must go out."

Save the full text in a file or DB with the short version as the file name or DB key. 将简短文本作为文件名或数据库密钥保存在文件或数据库中。

From the question: 从问题:

key is "Today is a sunny day." 关键是“今天是晴天”。
data is "Today is a sunny day. I must go out." 数据是“今天是晴天。我必须出去。”

If it is just during the duration of the app you can use a dictionary/hash table such as teh Java HashMap. 如果只是在应用程序运行期间,则可以使用字典/哈希表,例如Java HashMap。

The thing you want to do is not quite clear.It is not called encoding.It is just string manipulation. 您要做的事情还不太清楚,它不称为编码,只是字符串操作。 It might be that I am not understanding the thing clearly. 可能是我没有清楚地了解这件事。

String encoded = "Today is a sunny day. I must go out.";//Store encoded string here
String decoded = str.substring(0,str.indexOf('.')+1);//Store decoded string here

See if this helps... 看看是否有帮助...

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

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