我試圖刪除前導零/「0」來設置飛機的標題和音高,但我會怎麼做呢?在前幾次嘗試中,我使用CInt
函數將整數值轉換爲字符串值並將其轉換回整數,但這隻會產生錯誤。任何人都可以幫忙嗎?提前致謝。你會如何在vb.net中使用trimstart進行以下操作?
Dim pitchint As Integer
pitchint = Pitch_txt.Text
If pitchint > 720 Then
pitchint = pitchint - 720
Pitch_txt.Text = pitchint
Else
If pitchint > 360 Then
pitchint = pitchint - 360
Pitch_txt.Text = pitchint
End If
End If
If Pitch_txt.Text.Length <> 0 Then
If Pitchlbl.Text <> Pitch_txt.Text Then
Pitchlbl.Text = Pitch_txt.Text
End If
End If
以下是我會怎麼做,如果我想把pitchint爲一個字符串,然後返回到整數
Dim pitchint As String
pitchint = Pitch_txt.Text
pitchint = CInt(pitchint.TrimStart("0"))
If pitchint > 720 Then
pitchint = pitchint - 720
Pitch_txt.Text = pitchint
Else
If pitchint > 360 Then
pitchint = pitchint - 360
Pitch_txt.Text = pitchint
End If
End If
If Pitch_txt.Text.Length <> 0 Then
If Pitchlbl.Text <> Pitch_txt.Text Then
Pitchlbl.Text = Pitch_txt.Text
End If
End If
沒有錯誤,因爲不是在文本框和標籤返回的值的其他是相同的,即如果我輸入070返回的值是070沒有變化。
你能告訴用一個例子,你想達到什麼樣的? –
你想從pitchint整數中刪除零嗎? – Killingsworth
「Pitch_txt.Text」實際包含什麼?如果你使用'CInt'出錯,什麼錯誤? (「只是發現錯誤」不是對問題的描述,除非你說出你得到的錯誤是什麼。)如果這是VB.NET,爲什麼不使用'Int32.TryParse'來進行轉換從字符串到整數? –