如何在C#中查找StringBuilder的长度?

StringBuilder.Length属性用于获取或设置当前StringBuilder对象的长度。

语法:public int Length {get;set;}返回当前实例的长度。
异常:如果为set操作指定的值小于零或大于MaxCapacity, 则此属性将提供ArgumentOutOfRangeException。

下面的程序说明了上面讨论的属性的用法:

示例1:

//C# program to demonstrate
//the Length() Property
using System;
using System.Text;
  
class GFG {
  
     //Main Method
     public static void Main(String[] args)
     {
  
         //create a StringBuilder object
         //with a String passed as parameter
         StringBuilder str = new StringBuilder( "WelcomeGeeks" );
  
         //print string
         Console.WriteLine( "String = "
                    + str.ToString());
  
         //get length of StringBuilder object
         int length = str.Length;
  
         //print length
         Console.WriteLine( "length of String = "
                                      + length);
     }
}

输出如下:

String = WelcomeGeeks
length of String = 12

示例2:

//C# program to demonstrate
//the Length() Property
using System;
using System.Text;
  
class GFG {
     public static void Main(String[] args)
     {
  
         //create a StringBuilder object
         //with a String passed as parameter
         StringBuilder str = new StringBuilder( "India is Great" );
  
         //print string
         Console.WriteLine( "String = "
                    + str.ToString());
  
         //get length of StringBuilder object
         int length = str.Length;
  
         //print length
         Console.WriteLine( "length of String = "
                                      + length);
     }
}

输出如下:

String = India is Great
length of String = 14

参考:

  • https://docs.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.length?view=netframework-4.7.2

来源:

https://www.srcmini02.com/68641.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_39786.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?