?
Solved

Javascript finding some value from long string

Posted on 2013-06-19
9
Medium Priority
?
233 Views
Last Modified: 2013-06-21
Hi i have a string like this :

22208 : INCISE SPINE 3 COLUMN ADL SEGücertified~12/12/2012

The above string has following parts

Part 1: 22208 : INCISE SPINE 3 COLUMN ADL SEG [can be of any Length]

Part 2: ü [this is used as separator]

Part 3: certified [can be of value certified/noncertified/pending]

Part 4: ~ [this is again used as separator]

Part 5: 12/12/2012 [Date can be entered as mm/dd or mm/dd/yyyy or yyyy]

so i want do the part 3 and part 4 in separate alerts but i am caught in a mess here, my JS is not strong enough, here is my bit of try:

var index=myObject[row].indexOf("ü");
				var index2=myObject[row].indexOf("~");
				var statusCPT = myObject[row].substr(index+1)
				var statusCPT = statusCPT
				var statusDate = myObject[row].substr(index2+1)
				alert(statusCPT);
				alert(statusDate);

Open in new window

0
Comment
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 58

Assisted Solution

by:Julian Hansen
Julian Hansen earned 1000 total points
ID: 39259265
Do you man part 3 and 5 (4 appears to be a separator)

Why not find the first separator - change it to the second separator and then use the split function to get what you need?

Off the top of my head - have not had time to test

var indx = myObject[row].indexOf("ü");
myObject[row][indx] = '~';
var strs = myObject[row].split("~");
alert(strs[1]);
alert(strs[2]);
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 1000 total points
ID: 39259289
use split with regex:
var txt = myObject[row];
var tokens = txt.split(/[ü~]+/);
var part1 = tokens[0];
var status = tokens[1];
alert(status);
var date = tokens[2];
alert(date);

Open in new window

0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 39259318
Tested version using replace
var strs = myObject[row].replace("ü","~").split("~");
alert(strs[1]);
alert(strs[2]);

Open in new window

0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39259672
none of the above worked, showing 'undefined' every time
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39259981
I used the example u posted in the question.
Can u post the exact string u tested?
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 39260302
You have not posted how you get your data - where it comes from what it looks like. No other code other than the snippet you tried to solve the problem.

Based on your original post to working suggestions have been made.

You say they don't work - but you don't say

a) How you tested them
b) What data you tested them with.

It would be better for all concerned if you gave us as much info as possible in each of your posts so that we have a complete picture of

a) What you are wanting to do
b) What you have tried to do.
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39260307
will do, i am ooo now..

2marrow
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39265163
Tried the way i am doing it (I changed the ~ to S)

Here is my build in script:

destinationObject[destinationObject.length]=document.frmDiagEdit.DiagnosisCPT.value+'ü'+newstatus+'S'+newdateStatus;

the Last symbol can be available and it cannot be available . I am referring to this:

+'S'+newdateStatus;

on the all the string is build like this:

22208 : INCISE SPINE 3 COLUMN ADL SEGücertifiedS12/12/2012

it should give me 3 different rows in alerts separating all three and if the date is not defined at all, it show 2 only

that's all is in the script
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 39265213
If you are building the string yourself why not put in a standard delimiter - why put in the 'ü' and 'S'?

You can then use the standard split function to generate an array of strings which is then dead simple?
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 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