2016-05-31 67 views
-1

我是新来的Visual Basic。有人可以解释我如何创建一个可视化的基本字符串。这是在注册表中的路径中包含我不喜欢它删除注册表字符串中的字

程序文件\ GTA圣安地列斯\ gta_sa.exe

的一部分,我想使它像

程序文件\ GTA圣安地列斯

没有gta_sa.exe

我试过

Dim readValue As Object 
Dim dobijeno As String 
Dim playerName As Object 

readValue = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\SAMP", "gta_sa_exe", Nothing) 


dobijeno = readValue 

Dim withoutParts As String = Replace(dobijeno, "\gta_sa.exe", "") 

TextBox2.Text = readValue 

playerName = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\SAMP", "PlayerName", Nothing) 

TextBox1.Text = playerName 

但它不起作用

+0

你还没有真正解释你决定什么应该删除。如果你想删除最后一个“\”及其后的所有内容,最简单的方法是使用@AlastairBrown建议的'IO.Path.GetDirectoryName'来评论他的答案。另外,你应该阅读他的答案。 – Blackwood

+0

[Sock puppet/dupe account](http://stackoverflow.com/users/6393100/nathaniel)阅读[Ask]并参加[Tour],也许你的帐户不会被限制/ Q禁止 – Plutonix

回答

1

由于您只是分配到withoutParts,并且之后没有使用该变量,所以您似乎没有对替换结果进行任何操作。试试这个:

Dim withoutParts As String = Replace(dobijeno, "\gta_sa.exe", "") 

TextBox2.Text = withoutParts 
+1

另外,它看起来像你应该使用'Path.GetDirectoryName'而不是'Replace'。这就是'Dim withoutParts As String = Path.GetDirectoryName(dobijeno)' –