Solved

Strings and substring help

Posted on 2012-04-12
2
181 Views
Last Modified: 2012-04-12
I have 3 strings

myString1 = glengary
myString2 = glen gary glen ross xyz blah
myString3 = glengaryglenrossxyzblah
myString4 = ""

The values of these strings can (and will) change. I'm just using the assigned values as an example. The only thing for certain is that myString2 will always lead with myString1 (but may have spaces) and follow with unwanted text.

What is the best way to get to:
myString4 = glen gary
0
Comment
Question by:Mike Miller
2 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 37839983
Please try:
Dim myString1 = "glengary"
Dim myString2 = "glen gary glen ross xyz blah"
Dim myString3 = "glengaryglenrossxyzblah"
Dim myString4 = ""

Dim i1 As Integer, i2 As Integer = 0

For i1 = 0 To myString1.Length - 1
	While (myString2(i2) = " ")
		i2 += 1
	End While
	
	i2 += 1
Next

myString4 = myString2.Substring(0, i2)

Open in new window

0
 

Author Closing Comment

by:Mike Miller
ID: 37840026
This works. I ended up kind of doing something similar. I just created a loop that took off the last letter of the string until I got the desired value. Thanks!
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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