Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript finding some value from long string

Posted on 2013-06-19
9
Medium Priority
?
246 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
  • 4
  • 3
  • 2
9 Comments
 
LVL 60

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:
Meir Rivkin 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 60

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
Independent Software Vendors: 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!

 
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:Meir Rivkin
ID: 39259981
I used the example u posted in the question.
Can u post the exact string u tested?
0
 
LVL 60

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 60

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Suggested Courses

972 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