VB.net - performing the Trim function on a string question

Soldato
Joined
20 Oct 2002
Posts
6,212
Location
UK
basically when an event has happened i want to display the result in a label called lblbottom, the element i was to display is unknown until the end of the for loop its running in.. i've got it to display at the right time already just 1 problem

if the red spike wins the race it displays:

"THE WINNER IS THE COLOR [RED SPIKE"

the code im using to get this to display is below >>

lblbottom.Text = "The Winner is the " & spikes(a).colour.ToString.Trim("[", "]") & " Spike"

what i would like it to display is:

"THE WINNER IS THE RED SPIKE"

how would i do this ?!
 
Hows this

<%
Dim str, trStr As String
str = "[Hello World!]"
response.Write(str & "<br>")

Dim chArr() As Char = {"[", "]"}
trStr = str.Trim(chArr)
response.Write(trStr)
%>

?
 
paulsheff said:
<%
Dim str, trStr As String
str = "[Hello World!]"
response.Write(str & "<br>")

Dim chArr() As Char = {"[", "]"}
trStr = str.Trim(chArr)
response.Write(trStr)
%>

?

so youve set str as "[Hello World!]"

you've told it chArr refers to the charaters "[" and "]"

then set trStr to equal str with the values held in chArr trimmed off
 
Yep. Try:

Dim chArr() As Char = {"[", "]"}
lblbottom.Text = "The Winner is the " & spikes(a).colour.ToString.Trim(chArr) & " Spike"

and see what she does!
 
still getting the leading [ :(

check this over and see if its right, i've tried declaring chArr at the top of the code as well as in the if as it is below and neither worked

Private Sub Tmr200m_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tmr200m.Tick

Dim a = 0
For a = 0 To spikes.Length - 1
....spikes(a).clearSpike(drawarea, Color.White)
.... spikes(a).x = spikes(a).x + rand.Next(7, 14)
.... spikes(a).drawSpike(drawarea)
.... If spikes(a).x >= 469 Then
........Dim chArr() As Char = {"[", "]"}
........medal(a) = medal(a) + 1
........Tmr200m.Enabled = False
........lblbottom.Text = "The Winner is the " & spikes(a).colour.ToString.Trim(chArr) & " Spike"
........Exit For
....End If
Next a

End Sub
 
meh, found a longer way around it:

Dim winner As String
winner = "The Winner is the " & spikes(a).colour.ToString.Remove(0, 7) & "Spike"
lblbottom.Text = winner.Replace("]", " ")

iwin6ep.jpg
 
not really sure how i'd go about overriding the ToString() method, only been taught 10 hours of VB so im still relatively new to all of this
 
Back
Top Bottom