none
how do i delete a character in a string array word in C# RRS feed

  • Question

  • I am not well versed in C# but how do you delete a character to in a string array using a method format
    Tuesday, March 27, 2018 1:31 AM

Answers

  • Please do like this.
    (1) loop from the first element of a string array to the last 
    (2) replace a character you want to delete with blank.

    Regards


    Ashidacchi -- http://hokusosha.com/

    Tuesday, March 27, 2018 3:29 AM

All replies

  • Greetings Luke.

    I'm not sure what you mean. Can you give us an example of a string array and what you want to delete?

    Tuesday, March 27, 2018 2:03 AM
  • Please do like this.
    (1) loop from the first element of a string array to the last 
    (2) replace a character you want to delete with blank.

    Regards


    Ashidacchi -- http://hokusosha.com/

    Tuesday, March 27, 2018 3:29 AM
  • Hello lukew2251,

    Try the below code.

     static void Main(string[] args)
            {
                string str ="dsdfghjk;kf;sfksghdfj";
                string result = string.Empty;
                foreach (char ca in str) {
                    if (ca == 'd') {
                        continue;
                    }
                    result += ca;
                }
    
                Console.WriteLine(result);
                Console.ReadLine();
            }

    Best Regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 28, 2018 9:46 AM
    Moderator