Solved

Check for string????

Posted on 2007-04-07
7
195 Views
Last Modified: 2010-04-23
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

0
Comment
Question by:rkckjk
  • 5
  • 2
7 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 18869547
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
0
 
LVL 2

Author Comment

by:rkckjk
ID: 18869566
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
0
 
LVL 2

Author Comment

by:rkckjk
ID: 18869590
You can't convert a textbox to an array
0
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 63

Expert Comment

by:Fernando Soto
ID: 18869600
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")
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 18869608
The question did not say that the text string was in a text box.
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 18869635
This version will allow for more then two consecutive patterns without a space between them to be parsed.

        Dim pattern As String = "(\d+@.+?\.(?:net|com))"
        TextBox1.Text = Regex.Replace(TextBox1.Text, pattern, "$1")
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 18869856
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 ")
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question