In general, you need to somehow check for the presence and location of characters in the string.

For example, there is such a line:

Hello[]

PS [] - not an array, just a string.

You need to check the location of the characters "[]" and there, for example, put 1.

Type of such:

Hello [1]

How to do it?

Lines can be any, even though they are:

Good day, how are you? What should I do today? []

  • one
    string.Replace("[]", "[1]") ? - tym32167
  • Something is not working. Line: g = "Hello! How are you? []"; Replace: g.Replace ("[]", "[1]"); Exit: Hi! How are you? [] - CrazyProgrammist
  • g = g.Replace("[]", "[1]"); - tym32167
  • @CrazyProgrammist: Have you forgotten that the Replace function returns a new string? - VladD
  • one
    @VladD sir, have a sir! : D - tym32167

1 answer 1

To perform a search and replace in a string, you must use the function string.Replace ()

 var g = "Привет! Как дела?[]"; g = g.Replace("[]", "[1]"); Console.WriteLine(g); 

Conclusion

 Привет! Как дела?[1]