Solved

Remove a text string from the end of another string

Posted on 2016-11-07
5
20 Views
Last Modified: 2016-11-07
Hi

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?

Andy
0
Comment
Question by:Andy Green
  • 2
  • 2
5 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41877112
Hi,

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

Regards
0
 
LVL 3

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

Andy
0
 
LVL 48

Expert Comment

by:Rgonzo1971
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

0
 
LVL 32

Expert Comment

by:it_saige
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))
		Console.ReadLine()
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG
-saige-
0
 
LVL 3

Author Closing Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now