Solved

Replace everything after a space in a string

Posted on 2004-04-20
4
506 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

Technology Partners: 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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

756 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