JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 16th, 2005, 08:25 AM
linhardt linhardt is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: missouri
Posts: 165 linhardt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 27 m 51 sec
Reputation Power: 10
Parse characters of a string??

Need a little help trying to figure out the correct way to parse some characters of a string.

var X = "This is a Test, SHP - 1"

I need to get all the characters after the "SHP - ". There will be spaces in that substring. "SHP(space)-(space)"

Here are a few problems where it makes it more difficult for me.
When same characters are involved such as the "-".
If var X = "This is - a test, SHP - 1234"

The "SHP - " will always be at the end of the strings. So basically I need everything after that last (space) in "SHP - ".

Thanks!

Reply With Quote
  #2  
Old March 16th, 2005, 08:32 AM
wsa1971's Avatar
wsa1971 wsa1971 is offline
AYBABTU
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Here or There
Posts: 1,256 wsa1971 User rank is Major (30000 - 40000 Reputation Level)wsa1971 User rank is Major (30000 - 40000 Reputation Level)wsa1971 User rank is Major (30000 - 40000 Reputation Level)wsa1971 User rank is Major (30000 - 40000 Reputation Level)wsa1971 User rank is Major (30000 - 40000 Reputation Level)wsa1971 User rank is Major (30000 - 40000 Reputation Level)wsa1971 User rank is Major (30000 - 40000 Reputation Level)wsa1971 User rank is Major (30000 - 40000 Reputation Level)wsa1971 User rank is Major (30000 - 40000 Reputation Level)wsa1971 User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 35206 Folding Title: Starter FolderFolding Points: 35206 Folding Title: Starter Folder
Time spent in forums: 1 Month 2 Days 1 h 5 m 53 sec
Reputation Power: 374
Try this:
Code:
X.substring(X.indexOf('SHP - ')+6);
Where 6 is the length of the search String
__________________
A common mistake people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
Douglas Adams

Reply With Quote
  #3  
Old March 16th, 2005, 08:56 AM
Saint Jude Saint Jude is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 455 Saint Jude User rank is Lance Corporal (50 - 100 Reputation Level)Saint Jude User rank is Lance Corporal (50 - 100 Reputation Level)Saint Jude User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Days 3 h 4 m 22 sec
Reputation Power: 9
Send a message via Yahoo to Saint Jude
var X = "This is - a test, SHP - 1234";

/*--------------------------------
^ : string start
.* : any char sequence
--------------------------------*/
var digits = X.replace(/^.*SHP - /,'')

alert('|'+digits+'|')
Comments on this post
wsa1971 agrees: If you're comfortable using regular exp this is way more elegant!

Reply With Quote
  #4  
Old March 16th, 2005, 09:14 AM
linhardt linhardt is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: missouri
Posts: 165 linhardt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 27 m 51 sec
Reputation Power: 10
That does it. Thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Parse characters of a string??

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap