Hello everyone,

Im new here and may i have answer to my question since i been looking for sutoliton a long time ago,

I had a database looks like that

user:pass (<IP>)

user:pass (220.135.70.173:3128)

that i need is to remove the text between ( and ) and the symbols too.

to look like that

user:pass

Any help please, and if works with richtextbox, im using VB.NET 2010

Thanks in advance!

Eg:

user1:pass (186.5.126.106:8080)
user2:pass (49.212.49.76:3128)
user3:pass (200.122.132.113:8080)
user4:pass (110.171.32.139:3128)
user5:pass (182.71.162.28:3128)
user6:pass (111.118.179.232:3128)
user7:pass (200.68.19.130:3128)
user8:pass (190.82.87.11:3128)
user9:pass (220.135.70.173:3128)
user10:pass (61.7.214.42:8080)
user11:pass (31.3.249.91:8080)

To look like that without the IP and the ()

user1:pass
user2:pass
user3:pass
user4:pass
user5:pass
user6:pass
user7:pass
user8:pass
user9:pass
user10:pass
user11:pass

Dim str As String = "user8:pass (190.82.87.11:3128)"

'you can split either at the blank or the "("

Dim userpass As String

userpass = str.Split()(0)        'results in "user8:pass"
userpass = str.Split("(")(0)     'results in "user8:pass "

sorry but this code doesn't work for me, may u tell me where do i put this? im using richtextbox and button

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

'code i used

Dim str As String = RichTextBox1.Text
 Dim userpass As String
 userpass = str.Split()(0)
 userpass = str.Split("(")(0)
 End Sub
 End Class

You can simply remove all what us after parenthesis:

Dim str As String = "user1 pass (111.222.333)"
str = str.Remove(str.IndexOf("("C))

And put this code into a loop.

In what way does the code not work? Is it a syntax error when you type it in? Do you get an error message? If you get results, what are they?

Still nothing, when i cllick the button nothing happen, it stay user:pass ()

Thanks for the reply guys i very appreciate it

Dim str As String = "user8:pass (190.82.87.11:3128)"
'you can split either at the blank or the "("
Dim userpass As String
userpass = str.Split()(0) 'results in "user8:pass"
userpass = str.Split("(")(0) 'results in "user8:pass "

What happens when you run the following code

    Dim str As String = "user8:pass (190.82.87.11:3128)"

    Dim userpass As String = str.Split()(0)
    Msgbox (userpass)
Dim str As String = RichTextBox1.Text
                Dim userpass As String
                userpass = str.Split()(0)
            userpass = str.Split("(")(0)
            RichTextBox1.Text = userpass
            'this my code, works now... but not multiline how may i do multiline?
            Thanks

You don't have to use both lines of

    userpass = str.Split()(0)
    userpass = str.Split("(")(0)

I included both to show you that you could split the string on a blank (default) ar "(". You can probably get away with splitting on the blank as long as you are guaranteed that there is a blank before the "(". It would be wise to validate that RichTextBox1 contains a string that can be parsed in this way. If it does then you can simplify the code to

    RichTextBox1.Text = RichTextBox1.Text.Split()(0)

Can you please clarify what you mean by "how do I handle multiline?".

You need to loop through the RTF box line by line and pass the string (the line), through the Reverend Jims code

dim MyLines() as String
dim MyLine, userpass as string
dim i as integer = 0
MyLines = MyRTFControl.Lines

For i=0 to ubound(MyLines)
    MyLine = myLines(i)
    userpass = myLine.Split()(0)
    'do what you want to do with userpass
next

Or more concisely

For Each line As String In MyRTFControl.Lines
    userpass = line.Split()(0)
    'do what you want to do with userpass
next
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.