SORU
25 AĞUSTOS 2010, ÇARŞAMBA


Hangi metodu String sınıfında ilk N karakterleri verir sadece?

Ben yazmak ister uzatma yöntemi String sınıf böylece eğer giriş dizesi için daha uzun verilen uzunluk N sadece ilk N karakter görüntülenecek.

Gibi görünüyor:

public static string TruncateLongString(this string str, int maxLength)
{
    if (str.Length <= maxLength)
        return str;
    else
        //return the first maxLength characters                
}

6 ** yöntemi str N sadece ilk karakter almak için ne kullanabilirim?

CEVAP
25 AĞUSTOS 2010, ÇARŞAMBA


public static string TruncateLongString(this string str, int maxLength)
{
    return str.Substring(0, Math.Min(str.Length, maxLength));
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • hans peder sahl

    hans peder s

    22 Temmuz 2009
  • mobilenet.cz

    mobilenet.cz

    26 NİSAN 2008
  • NLthomas21

    NLthomas21

    20 Mayıs 2008