Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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 53

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 53

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 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