vb.net 获取字符串中的最后一个字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13194563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
get last character in a string
提问by clydewinux
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.
我是开发 Windows 手机应用程序的新手。现在我正在用 T9 键盘创建一个文本信使应用程序,我已经做了像按钮一样的设计。现在我想要的是如何获取字符串中的最后一个字符?例如字符串是“clyde”,如何从该字符串中获取字符“e”?我使用 Visual Basic 作为语言。
UPDATE: Got it working now, I used this code:
更新:现在可以使用了,我使用了以下代码:
string s = "clyde";
char e = s(s.Length-1);
回答by nothrow
I'm not sure about which language are you using, but in C# it is done like
我不确定您使用的是哪种语言,但在 C# 中是这样完成的
string s = "clyde";
char e = s[s.Length-1];
and it is very similar in every language.
它在每种语言中都非常相似。
回答by Derek
I would do this with linq :-
我会用 linq 做到这一点:-
string clyde = "Clyde";
char lastChar = clyde.Last();
Just my preference.
只是我的偏好。
回答by Claus J?rgensen
C#:
C#:
string clyde = "clyde";
char last = clyde[clyde.Length - 1];
VB.NET
网络
string clyde = "clyde";
char last = clyde(clyde.Length - 1);
回答by user3102516
C#:
C#:
String string = "string";
Char lastLetter = string[string.Length - 1];
VB.NET:
VB.NET:
Dim sInput As String = "sInput"
Dim lastLetter As Char = ChrW(sInput.Length - 1)
回答by FRocha
F#:
F#:
"input" |> Seq.last //val it : char = 't'
"input" |> Seq.last |> string //val it : string = "t"
回答by Tom
Dim s As String = "Clyde"
Dim s As String = "Clyde"
s = Mid(StrReverse(s), 1, 1)
s = Mid(StrReverse(s), 1, 1)