• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.
  • The forums have been upgraded with support for dark mode. By default it will follow the setting on your system/browser. You may override it by scrolling to the end of the page and clicking the gears icon.

vb.net question

Joined
Dec 22, 2007
Messages
184 (0.03/day)
Location
Central Nebraska
System Name CORSAIR
Processor AMD Phenom 1090T x6 @3.2
Motherboard Gigabyte Ga-78LMT-S2P
Cooling High efficiency dust cooling
Memory 8GB GSkill DDR3 1333
Video Card(s) Sapphire Radeon HD3870 512MB GDDR4 PCI-e toxic
Storage Seagate SV35.3 ST3250310SV 250GB SATAII(Windows 7 Pro x64), 320GB Samsung SATAII(Storage and SuSE)
Display(s) Dell 20" LCD, Dell 17" LCD
Power Supply Antec Cool Blue 650W Modular
Software Windows 7 Professional SP1, Visual Studio 2010 Ultimate
How would I identify specific words in a string? example "Hello my name is pat"
if i wanted to grab the 4th word from each string or only grab hi but using an identifier so I could take say the 2nd word from that string (my) or if the incoming string was "I like jam" then it would take (like)

???
 
if youre relating this topic to the one about IRC issue, use the previous one and shut this one down, mods dont take too kindly to having multiple posts about the same thing from the same person, as its known as Topic Spamming.

http://www.techpowerup.com/forums/showthread.php?t=173368

Patience is key, give it some time, you sometimes get an immediate answer other times you dont on the forums.
 
How would I identify specific words in a string? example "Hello my name is pat"
if i wanted to grab the 4th word from each string or only grab hi but using an identifier so I could take say the 2nd word from that string (my) or if the incoming string was "I like jam" then it would take (like)

???
Use .Split(Chr(32)) which will break it into an array of strings. Then you'd have to use the indexor on the array to get the fourth indexed item in the array. With it in array format, you can do whatever you want with each individual word.

32 is the ASCII character number for space. Chr() converts that number into the character type.
 
Last edited:
This was for a separate issue... figured i'd start a new thread for search purposes...
 
So how do i use the indexor to grab the 3rd word?
 
example:
Code:
Dim parts() As String = "Hello my name is pat".Split(Chr(32))
Console.WriteLine(parts(2))
Indexors are zero-based so 2 would be the third word.
 
ok...

Ok... so heres what I want... jsut need the one weird part figured out:
Code:
        Dim MessageParts() As String = TextBox_MsgOut.Text.Split(Chr(32))
        Dim WordCount As Integer = MessageParts.Length
        Dim ManualMessage As String = MessageParts(1, WordCount - 1)
        If MessageParts(0) = "/tell " Then
            ManualMessage = "PRIVMSG" & My.Settings.Channel & " " & ManualMessage
        End If
This line:
Code:
Dim ManualMessage As String = MessageParts(1, WordCount - 1)
I want to return the original text in the textbox - the "/tell "

I will use this for other commands where the first word isnt the only one needing to be looked for or excluded is why I ask in this way.

Any clue?
 
Would be easier just to do
Code:
If TextBox_MsgOut.Text.StartsWith("/tell ") Then
 
I know... but I need to make other commands... and I also need to use the same text to show me what I sent.
So far I have:
Code:
    Private Sub Button_send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_send.Click
        Dim InputMessage As String = TextBox_MsgOut.Text
        Dim MessageParts() As String = TextBox_MsgOut.Text.Split(Chr(32))
        Dim WordCount As Integer = MessageParts.Length
        Dim CutText As String = MessageParts(0) & " " & MessageParts(1)
        Dim CutCount As Integer = CutText.Length
        Dim ManualMessage As String = String.Join(" ", MessageParts)
        If MessageParts(0) = "/join" Then
            CurrentChannel = MessageParts(1)
            ManualMessage = "JOIN :" & MessageParts(1)
        ElseIf MessageParts(0) = "/tell" Then
            ManualMessage = "PRIVMSG " & MessageParts(1) & " " & ManualMessage.Remove(0, CutCount)
            TextBox_MsgIn.AppendText("TO " & MessageParts(1) & ": " & ManualMessage.Remove(0, CutCount) & vbCrLf)
        Else
            ManualMessage = "PRIVMSG " & CurrentChannel & " :" & ManualMessage
            TextBox_MsgIn.AppendText(My.Settings.Nick & ">>" & InputMessage & vbCrLf)
        End If

        Send(ManualMessage)
        TextBox_MsgOut.Clear()
    End Sub

But this is super ugly.
 
Basically what I want is a way to break input text down into words so I can remove MY clients commands and put it into IRC protocol form before sending. I also want to display it cleaner than displaying the RAW IRC protocol data I'm sending.
 
Aren't all IRC commands a single word? Why not use a Select...Case...End Select block?
Code:
Select MessageParts(0).ToLower
  Case "/join"
    'do something
  Case "/tell"
    'do something else
  Case Else
   Dim output As String = MessageParts(0)
   For i As Integer = 1 To MessageParts.Length
     output = output & " " & MessageParts(i)
   Next
End Select
 
+1 for Select...Case...End Select. Also, you can use "RegularExpressions" to find words/Characters in text as well. :toast: I wouldn't re invent the wheel, and change from String.Split Method. I just wanted to share another way. Your in good hands with Ford he is a very knowledgeable fellow. :toast:
 
Back
Top