473,411 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

string parsing

Hi,
I can't figure out how to parse the following string and to decompose
it into substring.

CuttingFlags--C500F2*#C503F3*#C509F10*#C506F2*F15##

Basically, each C should go in an array. and for each C I should have
an array of F.

CuttingFlags array contains C500, C503, C509 and C506

C500 contains F2, C506 contains F2 and F15.....

Can you help to parse the string first ?

Thanks

Jun 21 '06 #1
2 6591
sa*************@googlemail.com wrote:
I can't figure out how to parse the following string and to decompose
it into substring.

CuttingFlags--C500F2*#C503F3*#C509F10*#C506F2*F15##

Basically, each C should go in an array. and for each C I should have
an array of F.

CuttingFlags array contains C500, C503, C509 and C506

C500 contains F2, C506 contains F2 and F15.....

Can you help to parse the string first ?


I believe the following should do the trick:

var str = 'C500F2*#C503F3*#C509F10*#C506F2*F15##';
var spl = str.split('#');
var results = new Array();

for (i=0; i<spl.length; ++i) {
if (spl[i] && spl[i] != '') {
var k = spl[i].split('F');
k[0] = k[0].replace(/^C/,'');
results[k[0]] = 'F'+k[1];
for (j=2; j<k.length; ++j) {
results[k[0]]+='F'+k[j];
}
}
}

for (i=0; i<results.length; ++i) {
if (results[i] && results[i]!='') {
var es = results[i].split('*');
document.writeln('<hr><big>C'+i+' contains:</big><br>');
for (j=0; j<es.length; ++j) {
if (es[j] && es[j]!='') {
document.writeln(es[j]+'<br>');
}
}
}
}

Hope this helps,

--
Bart

Jun 21 '06 #2
That was fun! :p
Bart Van der Donck wrote:
sa*************@googlemail.com wrote:
I can't figure out how to parse the following string and to decompose
it into substring.

CuttingFlags--C500F2*#C503F3*#C509F10*#C506F2*F15##

Basically, each C should go in an array. and for each C I should have
an array of F.

CuttingFlags array contains C500, C503, C509 and C506

C500 contains F2, C506 contains F2 and F15.....

Can you help to parse the string first ?


I believe the following should do the trick:

var str = 'C500F2*#C503F3*#C509F10*#C506F2*F15##';
var spl = str.split('#');
var results = new Array();

for (i=0; i<spl.length; ++i) {
if (spl[i] && spl[i] != '') {
var k = spl[i].split('F');
k[0] = k[0].replace(/^C/,'');
results[k[0]] = 'F'+k[1];
for (j=2; j<k.length; ++j) {
results[k[0]]+='F'+k[j];
}
}
}

for (i=0; i<results.length; ++i) {
if (results[i] && results[i]!='') {
var es = results[i].split('*');
document.writeln('<hr><big>C'+i+' contains:</big><br>');
for (j=0; j<es.length; ++j) {
if (es[j] && es[j]!='') {
document.writeln(es[j]+'<br>');
}
}
}
}

Hope this helps,

--
Bart


Jun 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Kai Jaensch | last post by:
Hello, i am an newbie and i have to to solve this problem as fast as i can. But at this time i donīt have a lot of success. Can anybody help me (and understand my english :-))? I have a...
18
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
50
by: z. f. | last post by:
HI, i have string in format dd/mm/yyyyy hh:mm:ss and giving this as an input to DateTime.Parse gives a string was not recognized as a valid date time format string error. how do i make the parse...
9
by: Python.LeoJay | last post by:
Dear all, i need to parse billions of numbers from a file into float numbers for further calculation. i'm not satisfied with the speed of atof() function on my machine(i'm using visual c++ 6)....
4
by: Michael Meckelein | last post by:
Hello, Wondering, if C# (framework 2.0) does not support parsing DateTime timezones in three letter acronyms. I would like to parse date strings like "2005 Nov 01 11:58:47.490 CST -6:00" but...
3
by: dimasteg | last post by:
Hi all C. Nead some help with string "on the fly" parsing, how it can be realized ? Any ideas? I got some of my own, but it's interesting to get other points of view . Regards.
9
balabaster
by: balabaster | last post by:
I'm looking for some ideas regarding string parsing and brackets. Say I have the following string: 56*(73+23/(28+(7/14)-(3/2)) What would be the best way to parse the string for each opening...
6
by: James Arnold | last post by:
Hello, I am new to C and I am trying to write a few small applications to get some hands-on practise! I am trying to write a random string generator, based on a masked input. For example, given...
6
by: (2b|!2b)==? | last post by:
I am expecting a string of this format: "id1:param1,param2;id2:param1,param2,param3;id" The tokens are seperated by semicolon ";" However each token is really a struct of the following...
1
by: eyeore | last post by:
Hello everyone my String reverse code works but my professor wants me to use pop top push or Stack code and parsing code could you please teach me how to make this code work with pop top push or...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.