Solved

Splitting variable into 2 values

Posted on 2006-11-15
5
219 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
[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
  • 2
  • 2
5 Comments
 
LVL 86

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 86

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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 …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses

627 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