我如何替换字符串数组中的项? [英] How do I replace an item in a string array?

查看:98
本文介绍了我如何替换字符串数组中的项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C#我怎么在一个字符串数组替换项目文本,如果我不知道持何立场?

Using C# how do I replace an item text in a string array if I don't know the position?

我的数组为[柏林,伦敦,巴黎]我怎么与纽约取代巴黎?

My array is [berlin, london, paris] how do I replace paris with new york?

推荐答案

您需要通过指数来解决这个问题:

You need to address it by index:

arr[2] = "new york";

既然你说你不知道的位置,你可以使用Array.IndexOf找到它:

Since you say you don't know the position, you can use Array.IndexOf to find it:

arr[Array.IndexOf(arr, "paris")] = "new york";  // ignoring error handling

这篇关于我如何替换字符串数组中的项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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