Solved

Remove a text string from the end of another string

Posted on 2016-11-07
5
38 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
[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
  • 2
5 Comments
 
LVL 51

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 51

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 34

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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