Reputation: 515
I am new to developing windows phone apps. Now I am creating a text messenger app with T9 keyboard, I already made design like the buttons. Now what I want is how can I get the last character in a string? Example the string is "clyde", how can I get the char 'e' from that String? I am using Visual Basic as language.
UPDATE: Got it working now, I used this code:
string s = "clyde";
char e = s(s.Length-1);
Upvotes: 7
Views: 75756
Reputation: 26341
C#:
string clyde = "clyde";
char last = clyde[clyde.Length - 1];
VB.NET
Dim clyde as String = "clyde"
Dim last as Char = clyde(clyde.Length - 1)
Upvotes: 10
Reputation: 960
F#:
"input" |> Seq.last //val it : char = 't'
"input" |> Seq.last |> string //val it : string = "t"
Upvotes: 0
Reputation: 97
C#:
String string = "string";
Char lastLetter = string[string.Length - 1];
VB.NET:
Dim sInput As String = "sInput"
Dim lastLetter As Char = ChrW(sInput.Length - 1)
Upvotes: 3
Reputation: 8628
I would do this with linq :-
string clyde = "Clyde";
char lastChar = clyde.Last();
Just my preference.
Upvotes: 6
Reputation: 16168
I'm not sure about which language are you using, but in C# it is done like
string s = "clyde";
char e = s[s.Length-1];
and it is very similar in every language.
Upvotes: 10