Solved

Replace everything after a space in a string

Posted on 2004-04-20
4
467 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
  • 2
4 Comments
 
LVL 8

Expert Comment

by:dishanf
Comment Utility
can you explan little more
You want this.
"SONY ELECTRONICS" --> "ELECTRONICS" ???
0
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

744 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

17 Experts available now in Live!

Get 1:1 Help Now