🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# RMOS / birden fazla boşluğu teke düşürme regex

1-) C# RMOS - birden fazla boşluğu teke düşürme

 

 

      string sentence = "This is a sentence with multiple    spaces";

            RegexOptions options = RegexOptions.None;

            Regex regex = new Regex("[ ]{2,}", options);

            sentence = regex.Replace(sentence, " ");

 

 

kaynak : https://stackoverflow.com/questions/206717/how-do-i-replace-multiple-spaces-with-a-single-space-in-c

 

 

 

 

SADECE A DAN Z YE VE BOŞLUK OLSUN DİĞERLERİNİ SİL DEMEK

 

   text = Regex.Replace(text, @"[^A-Za-z_ğüşıöçĞÜŞİÖÇ\s<]", string.Empty);

 

 

İKİ KARAKTERDEN KÜÇÜK OLANLARI SİL YANİ TEK KARAKTERLİLERİ

 string[] splits = text.Split(' ');

 

            string yeniText = "";

            for (int i = 0; i < splits.Length; i++)

            {

                if (splits[i].Length > 1)

                {

                    yeniText += splits[i]+" ";

                }

            }

            yeniText = yeniText.Trim();

 2022 Şubat 22 Salı
 427