为什么字符串是不可变的? [英] Why are strings immutable?

查看:125
本文介绍了为什么字符串是不可变的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我讨厌将字符串转换为列表,操纵它,然后将b / b转换回字符串。为什么不让字符串变得可变?

I kind of hate to have to convert a string into a list, manipulate it, and
then convert it back into a string. Why not make strings mutable?

推荐答案

2004年8月21日星期六03:26:00 GMT,

布伦特W 。休斯< br ********** @ comcast.net>写道:
On Sat, 21 Aug 2004 03:26:00 GMT,
Brent W. Hughes <br**********@comcast.net> wrote:
我讨厌将字符串转换为列表,操纵它,然后将其转换回字符串。为什么不让字符串变得可变?
I kind of hate to have to convert a string into a list, manipulate it, and
then convert it back into a string. Why not make strings mutable?




无法使用字符串作为字典键会有点吮吸:)


- -

Sam Holden



Not being able to use strings as dictionary keys would kind of suck :)

--
Sam Holden


Brent W. Hughes写道:
Brent W. Hughes wrote:
我讨厌有将字符串转换为列表,操纵它,然后将其转换回字符串。为什么不让字符串变得可变?
I kind of hate to have to convert a string into a list, manipulate it, and
then convert it back into a string. Why not make strings mutable?




你不可能做任何你需要做的事情

如果你以最好的方式做到这一点正在转换成一个列表并且返回
。这里的用例是什么?你能描述一下你需要完成什么,而不考虑你认为应该如何实现
?也许有更好的方式......


-Peter



It is unlikely you are doing whatever it is you need to do
in the best way possible if you are converting to a list and
back. What''s the use case here? Can you describe what you
need to accomplish without reference to how you think it should
be accomplished? Maybe there''s a better way...

-Peter


嗨布伦特,


通常最好创建一个功能,你可以在其中兑换
1)将字符串传递给

2)根据需要更改

3)将修改过的蜇回到原来的来电者。


你能告诉我们一些你想要完成的事吗?


Byron

---

Brent W. Hughes写道:
Hi Brent,

It is usually best to create a function in which you can
1) pass the string to
2) change it as needed
3) return the modified sting back to the original caller.

Can you tell us a little more about what you are trying to accomplish?

Byron
---
Brent W. Hughes wrote:
我讨厌将字符串转换为列表,操纵它,然后将其转换回字符串。为什么不把字符串变成可变的?
I kind of hate to have to convert a string into a list, manipulate it, and
then convert it back into a string. Why not make strings mutable?



这篇关于为什么字符串是不可变的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆