Solved

Splitting variable into 2 values

Posted on 2006-11-15
5
178 Views
Last Modified: 2010-04-23
I have the following value in the variable sExerciseStage:

The Motor Bike Starter(stage1)

I need "The Motor Bike Starter" to be assigned to a new variable sExercise
and the # "1" to be assigned to a new variable iStage

Can anyone help me split this? Thanks

0
Comment
Question by:wilcor14
  • 2
  • 2
5 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17948276
Many ways to do it...

Here's one:

        Dim sExerciseStage As String = "The Motor Bike Starter(stage1)"

        Dim parts() As String = sExerciseStage.Split("(".ToCharArray)

        Dim sExercise As String = parts(0).Trim
        Dim iStage As Integer = Integer.Parse(parts(1).Replace("stage", "").TrimEnd(")").Trim)

        Debug.WriteLine("sExercise = " & sExercise)
        Debug.WriteLine("iStage = " & iStage)
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 17948294
Hi wilcor14,

System.Text.RegularExpressions.Regex.Split("The Motor Bike Starter(stage1)", "\\(stage");

Cheers!
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17948354
wilcor14,

We have both made assumptions about the source string...

For a bulletproof solution, answer these questions:

    Will there always be a "(" after the first part?

    Will there always be a trailing ")" at the end?

    Will "stage" ALWAYS be before the number you want?

If "No" to either then please post some examples of the strings you need parsed...
0
 

Author Comment

by:wilcor14
ID: 17948378
Idle_Mind,

Your assumptions are correct. I'm testing it right now and I think this will work perfect. Give me a few moments.
0
 

Author Comment

by:wilcor14
ID: 17953509
It works perfectly. Sorry for the delay. Thanks for your help.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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 …
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

13 Experts available now in Live!

Get 1:1 Help Now