How to get first character of string?
string test = "StackOverflow";
first character = "S"
Using the isDigit() method Therefore, to determine whether the first character of the given String is a digit. The charAt() method of the String class accepts an integer value representing the index and returns the character at the specified index.
Kotlin string indexing We can get specific characters from a string with indexing operations. The example shows how to get the first and last characters of a string. It uses indexing operations and alternative string methods. The indexes start from zero; therefore, the first character has zero index.
You call the Substring(Int32, Int32) method to extract a substring from a string that begins at a specified character position and ends before the end of the string. The starting character position is a zero-based; in other words, the first character in the string is at index 0, not index 1.
String test = "StackOverflow"; char first = test.charAt(0);
Another way is
String test = "StackOverflow"; String s=test.substring(0,1);
In this you got result in String
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With