Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
StringBuilder.Chars[] Property in C#
The StringBuilder.Chars[] property gets or sets the character at the specified character position in this instance.
Syntax
The syntax is as follows -
public char this[int index] { get; set; }
Above, the index parameter is the position of the character.
Example
Let us now see an example -
using System;
using System.Text;
public class Demo {
public static void Main() {
StringBuilder strBuilder = new StringBuilder("ghgh78hkjj");
int num = 0;
for (int i = 0; i < strBuilder.Length; i++) {
char c = strBuilder[i];
if (Char.IsDigit(c))
num++;
}
Console.WriteLine("String = "+strBuilder);
Console.WriteLine("Numbers in the string = "+num);
}
}
Output
This will produce the following output -
String = ghgh78hkjj Numbers in the string = 2
Example
Let us now see another example -
using System;
using System.Text;
public class Demo {
public static void Main() {
StringBuilder strBuilder = new StringBuilder("ghgh78hkjj");
char c = strBuilder[3];
Console.WriteLine("String = "+strBuilder);
Console.WriteLine("Character = "+c);
}
}
Output
This will produce the following output -
String = ghgh78hkjj Character = h
Advertisements
