Solved

Replace everything after a space in a string

Posted on 2004-04-20
4
515 Views
Last Modified: 2012-06-27
HI,
As the replace fn does not accept wildcards, how do I remove all characters in a string, AFTER the first space is encountered?
Ie; the original string may read: SONY ELECTRONICS
What I want this to be replaced with is simply: SONY

thanks!
Fergal
0
Comment
Question by:fjkilken
[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
4 Comments
 
LVL 8

Expert Comment

by:Dishan Fernando
ID: 10867044
can you explan little more
You want this.
"SONY ELECTRONICS" --> "ELECTRONICS" ???
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 10867091
Hi fjkilken,

How about

Left(MyField,CharIndex(' ',MyField)-1)

Tim Cottee
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 

Author Comment

by:fjkilken
ID: 10867232
The solution: "Left(MyField,CharIndex(' ',MyField)-1)" probably won't work as I do not know how many characters ( for the CHAR INDEX) will be in the string, ie; it could be SONY ELECTROINCS or just as easilt: PHILIPPS INDUSTRIES
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 250 total points
ID: 10867259
fjkilken,

That is the point, CharIndex tells you where the first space is in the string then takes everything to the left of that. Of course if it is an empty string it will fail but you can simply handle that with:

Left(MyField + ' ',CharIndex(' ',MyField + ' ') -1)

Tim.
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

724 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