如何在 C# 中計算字串長度?
在 C# 中使用 String.Length 屬性可獲取字串長度。
str.Length
該屬性可計算字串中的單詞並顯示指定字串的長度,例如,字串 Amit 具有 4 個字元 -
string str = "Amit";
示例
以下是計算字串長度的 C# 程式 -
using System;
using System.Collections;
namespace Demo {
class Program {
static void Main(string[] args) {
string str = "Amit";
Console.WriteLine("String: "+str);
Console.WriteLine("String Length: "+str.Length);
Console.ReadKey();
}
}
}輸出
String: Amit String Length: 4
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP