2016-05-31 64 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)' –