Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Check for string????

Posted on 2007-04-07
7
Medium Priority
?
218 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:Richard Kreidl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 64

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:Richard Kreidl
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:Richard Kreidl
ID: 18869590
You can't convert a textbox to an array
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 64

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 64

Expert Comment

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

Accepted Solution

by:
Fernando Soto earned 2000 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 64

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 Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

704 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