?
Solved

Strings and substring help

Posted on 2012-04-12
2
Medium Priority
?
185 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
[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 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 2000 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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 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