tags:

views:

153

answers:

1

Hi all,

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?

Mnay thanks

+9  A: 

You need to address it by index:

arr[2] = "new york";

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
itowlson
Many thanks for this.
Jade M
Why would IndexOf be unavailable in my array? I'm targeting .Net 3.5 Thanks
Jade M
Mea culpa, Jade M, I am used to working with lists and didn't check the method docs. Sorry for the bad steer, answer updated.
itowlson