• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

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:


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.


Richard Kreidl
Richard Kreidl
  • 5
  • 2
1 Solution
Fernando SotoRetiredCommented:
Hi rkckjk;

This will do what you need.

Imports System.Text.RegularExpressions

        ' Test Data
        Dim input() As String = {"5555550129@archwireless.net5555550139@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

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

Richard KreidlSoftware DeveloperAuthor Commented:
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
Richard KreidlSoftware DeveloperAuthor Commented:
You can't convert a textbox to an array
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Fernando SotoRetiredCommented:
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")
Fernando SotoRetiredCommented:
The question did not say that the text string was in a text box.
Fernando SotoRetiredCommented:
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")
Fernando SotoRetiredCommented:
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 ")
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now