Remove a text string from the end of another string

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

I'm using Asp.net 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
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
LVL 52

Accepted Solution

Rgonzo1971 earned 2000 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 52

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 34

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 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