Solved

Check for string????

Posted on 2007-04-07
7
177 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 62

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 62

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 62

Expert Comment

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

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 62

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now