Vb.net 替换字符串中的最后一个字符

Vb.net 替换字符串中的最后一个字符,vb.net,string,windows-phone-7,Vb.net,String,Windows Phone 7,我还有一个关于VisualBasic的问题,我现在在为WindowsPhone7.5开发应用程序时使用的语言。我的问题是如何替换字符串中的最后一个字符?例如,我有字符串“clyde”,现在我想用“o”替换最后一个字符“e”,但我该怎么做呢?任何帮助都将不胜感激。编辑:现在已测试(我忘记添加名称空间) myString=Microsoft.VisualBasic.Left(myString,Len(myString)-1)和myNewChar 例如: 尝试了一些在线VB转换器 Dim str As

我还有一个关于VisualBasic的问题,我现在在为WindowsPhone7.5开发应用程序时使用的语言。我的问题是如何替换字符串中的最后一个字符?例如,我有字符串“clyde”,现在我想用“o”替换最后一个字符“e”,但我该怎么做呢?任何帮助都将不胜感激。

编辑:现在已测试(我忘记添加名称空间)

myString=Microsoft.VisualBasic.Left(myString,Len(myString)-1)和myNewChar

例如:

尝试了一些在线VB转换器

Dim str As String = "clyde"
str = str.Substring(0, str.Length - 1) & "o"C
在vb.net脚本中:

  Dim s As String

  Sub Main()
    s = "hello world"
    s = s.Substring(0, s.Length - 1)  &  "o"

    Console.WriteLine(s)
    Console.ReadLine()
  End Sub

我在CodeProjectHey上提出了一个String类的扩展>>嘿,你说得对!@nkchandra有正确的解决方案…修复了它
Dim str As String = "clyde"
str = str.Substring(0, str.Length - 1) & "o"C
  Dim s As String

  Sub Main()
    s = "hello world"
    s = s.Substring(0, s.Length - 1)  &  "o"

    Console.WriteLine(s)
    Console.ReadLine()
  End Sub
Imports Microsoft.VisualBasic
Imports System.Runtime.CompilerServices

Public Module StringExtensions

<Extension()> _
Public Function ReplaceFirstChar(str As String, ReplaceBy As String) As String
    Return ReplaceBy & str.Substring(1)
End Function

<Extension()> _
Public Function ReplaceLastChar(str As String, ReplaceBy As String) As String
    Return str.Substring(0, str.Length - 1) & ReplaceBy
End Function

End Module
dim s as String= "xxxxx"
msgbox (s.ReplaceFirstChar("y"))
msgbox (s.ReplaceLastchar ("y"))