Link to home
Start Free TrialLog in
Avatar of Richard Kreidl
Richard KreidlFlag for United States of America

asked on

Check for string????

How would you use "instr" to check for a particular type of string?

I need to check strings like the following strings:

5555550129@archwireless.net5555550139@archwireless.net
5555550129@archwireless.com5555550139@archwireless.net

that I need to separate like this:

5555550129@archwireless.net 5555550139@archwireless.net
5555550129@archwireless.com 5555550139@archwireless.net

So, I somehow need to check if there is a "t" or a "c" followed by a number and then add a space bewteen the "t" or "c" and the number.

thanks

Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi rkckjk;

This will do what you need.

Imports System.Text.RegularExpressions

        ' Test Data
        Dim input() As String = {"5555550129@archwireless.net5555550139@archwireless.net", _
            "5555550129@archwireless.com5555550139@archwireless.net"}
        ' The Regular Expression pattern to parse the input
        Dim pattern As String = "(\d+@archwireless.(?:net|com))(\d+@archwireless.(?:net|com))"
        Dim idx As Integer = 0

        For Each email As String In input
            ' Parse the input
            input(idx) = Regex.Replace(input(idx), pattern, "$1 $2")
            idx += 1
        Next

        ' Display Results
        MessageBox.Show(input(0) & Environment.NewLine & input(1))

Fernando
Avatar of Richard Kreidl

ASKER

Sorry, I should have mentioned the string data is in a textbox and also archwireless is not a constant. It could be sprintpcs or other providers
You can't convert a textbox to an array
Same thing just different input and a small change to the pattern allowing any domain.

        Dim pattern As String = "(\d+@.+?\.(?:net|com))(\d+@.+?\.(?:net|com))"
        TextBox1.Text = Regex.Replace(TextBox1.Text, pattern, "$1 $2")
The question did not say that the text string was in a text box.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry missed a space after the $1 below

        Dim pattern As String = "(\d+@.+?\.(?:net|com))"
        ' Should be this
        TextBox1.Text = Regex.Replace(TextBox1.Text, pattern, "$1 ")