Wednesday, August 17, 2022

[FIXED] How to ignore specific char while reading SpeechSynthesizer C#?

Issue

I have some string which goes as follows

TEST___5____345

How can I make SpeechSynthesizer to ignore the underscore chars while reading, as its annoying ?


Solution

The code below splits your string using the underscore as the separator. Adding the StringSplitOptions.RemoveEmptyEntries removes all empty string that would occur when multiple sequential underscores are in your inputstring.

using System;

namespace IgnoreUnderscore
{
    class Program
    {
        static void Main(string[] args)
        {
            var str ="TEST___5____345";

            var arr = str.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine(arr[i]);
            }

            Console.ReadKey();
        }
    }
}

Output is


TEST
5
345



Answered By - Paul Sinnema
Answer Checked By - Candace Johnson (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.