Remove a text string from the end of another string

Posted on 2016-11-07
Last Modified: 2016-11-07

I'm using VB, and have a string containing someone's name along with a location in brackets, I need to find the position of the Location and remove it from the string for display purposes.

ie Andy (Home) Mon - Wed need to display Andy Or John (Office) Tues Wed & Thurs needs to display John.

Is there a simples way to do this?

Question by:Andy Green
  • 2
  • 2
LVL 49

Accepted Solution

Rgonzo1971 earned 500 total points
ID: 41877112

pls try
      Dim sentence As String = "Andy (Home) Mon - Wed "
      Dim name As String = sentence.Split(New Char() {"("c})(0).TrimEnd(New Char() {" "c})

Open in new window


Author Comment

by:Andy Green
ID: 41877129
Thanks but I get the error Visual Basic 12 does not support multiline literals, it doesn't like the "c

LVL 49

Expert Comment

ID: 41877142
then try
      Dim sentence As String = "Andy (Home) Mon - Wed "
      Dim name As String = sentence.Split(CChar("("))(0).TrimEnd(CChar(" "))

Open in new window

LVL 33

Expert Comment

ID: 41877152
Same premise as Rgonzo but just simplifying the split assuming that you use that specific format; e.g. - FirstName (Location) Day(s) -
Dim sentence As String = "Andy (Home) Mon - Wed"
Dim uiName = sentence.Split(" ")(0)

Open in new window

Proof of concept -
Module Module1
	Sub Main()
		Dim data1 As String = "Andy (Home) Mon - Wed"
		Dim data2 As String = "John (Office) Tues Wed & Thurs"

		Console.WriteLine(data1.Split(" ")(0))
		Console.WriteLine(data2.Split(" ")(0))
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG

Author Closing Comment

by:Andy Green
ID: 41877153
Excellent thank you - problem first time was I'd not copied the entire length of answer.

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

831 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