Hi I am new to DXL. Can we possible to extact the integres from the string.. |
Re: Extracting Integers from a string
Easy. With a regexp you can find all numbers in a string:
Regexp r = regexp "[0-9]+"
int pos = 0
string s = "0123, 3456, 12"
// create a buffer so we can iterate over all matches efficiently
Buffer buf = create(); buf = s
while (search(r, buf, pos)) {
int nr = intOf realOf s[pos+start 0:pos+end 0]
print nr // do whatever you like with the nr
pos += 1 + end 0
}
delete buf
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Extracting Integers from a string Mathias Mamsch - Fri Oct 05 17:37:13 EDT 2012
Easy. With a regexp you can find all numbers in a string:
Regexp r = regexp "[0-9]+"
int pos = 0
string s = "0123, 3456, 12"
// create a buffer so we can iterate over all matches efficiently
Buffer buf = create(); buf = s
while (search(r, buf, pos)) {
int nr = intOf realOf s[pos+start 0:pos+end 0]
print nr // do whatever you like with the nr
pos += 1 + end 0
}
delete buf
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Thanks for your post reg how to extract the numeric data to strings. I have a string like s= "N11.03N11.02N10.00N11.00N12.00" I want to extract the string like the o/p below 1103 1102 1000 1100 1200 Each integer needs to stored and it needs to be compared with other string/int |
Re: Extracting Integers from a string SystemAdmin - Mon Feb 04 04:34:55 EST 2013 So which part of it is the problem? For the extraction of the numbers, you can use the same code as above, just a different regular expression. Then inside the search loop you will convert to Integer and put the numbers to a Skip list. int val = intOf ( realOf (strYouIntegerString) ) put (yourSkip, val, val)
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Extracting Integers from a string Mathias Mamsch - Mon Feb 04 07:46:26 EST 2013 So which part of it is the problem? For the extraction of the numbers, you can use the same code as above, just a different regular expression. Then inside the search loop you will convert to Integer and put the numbers to a Skip list. int val = intOf ( realOf (strYouIntegerString) ) put (yourSkip, val, val)
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Can you give me the Regular expression syntax? I have used the similar syntax but it didnt work. If you dont mind, can you provide me the Regular expression, and how to club the numeric data and then compare by example? |
Re: Extracting Integers from a string SystemAdmin - Mon Feb 04 08:56:19 EST 2013 Regexp r = regexp "0-9" to extract the numbers. But each number is printed in one line, but I need to club the int like 1103 or 1102 from N11.03. how to put the numbers in one string? Sorry I am very new to DXL and also coding. |
Re: Extracting Integers from a string SystemAdmin - Mon Feb 04 08:59:24 EST 2013
Your regular expression would be something like: // match 1 match 2 // N (digits) . (digits) Regexp re = regexp "N([0-9]+)\\.([0-9]+) // ... // concatenate match 1 and match 2 string sMyNumberString = s[pos+start 1:pos+end 1] s[pos+start 2:pos+end 2] int myNumber = intOf realOf sMyNumberString
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Extracting Integers from a string Mathias Mamsch - Mon Feb 04 15:22:23 EST 2013
Your regular expression would be something like: // match 1 match 2 // N (digits) . (digits) Regexp re = regexp "N([0-9]+)\\.([0-9]+) // ... // concatenate match 1 and match 2 string sMyNumberString = s[pos+start 1:pos+end 1] s[pos+start 2:pos+end 2] int myNumber = intOf realOf sMyNumberString
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Your input really worked. Thanks a lot. First while loop is taking and that only for one Object in the module. Second while is not taking at all. My intention is to extract the Numeric data from attribute Release and Tar. Then I wanted to compare the numeric data from those attributes if it is <= 1103 and then set the value implemented. I tried by removing the while loop and made it with if condition. Then it is taking only first numeric data from the mentioned attributes. Please help me how to extract all the data for a attribute of Object and then compare. Danke SChon Attachments attachment_14937167_DXL.txt |
Re: Extracting Integers from a string SystemAdmin - Tue Feb 05 06:11:29 EST 2013 |
Re: Extracting Integers from a string llandale - Tue Feb 05 10:58:15 EST 2013 But how to remove the carraige return ( newline character from the extracted string) and keep the data to array as integer? Currently the o/p is like below: 1103 1102 1201 1000 I would like to have the above data stored in array like : { 1103,1102,1201,1000} |
Re: Extracting Integers from a string SystemAdmin - Wed Feb 06 01:37:35 EST 2013
From the above post you already see how to convert the number strings to integers using intOf realOf. Now you can just store them in an array like this:
Array arNumbersFound = create(10,2) // array will atomatically resize, so do not worry about the overall size
int iFound = 0
// ...
// in your search loop:
int val = intOf realOf myStringValue
put (arNumbersFound, val, iFound, 0 /* = first column */)
iFound++
// Later to iterate over the array:
int i
print "Values: "
for (i = 0; i < iFound; i++) {
int value = (get(arNumbersFound, i, 0 /* = first column */)
if (i != 0) print ", " // print or do whatever you like with the numbers
print value ""
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Extracting Integers from a string Mathias Mamsch - Thu Feb 07 04:08:20 EST 2013
From the above post you already see how to convert the number strings to integers using intOf realOf. Now you can just store them in an array like this:
Array arNumbersFound = create(10,2) // array will atomatically resize, so do not worry about the overall size
int iFound = 0
// ...
// in your search loop:
int val = intOf realOf myStringValue
put (arNumbersFound, val, iFound, 0 /* = first column */)
iFound++
// Later to iterate over the array:
int i
print "Values: "
for (i = 0; i < iFound; i++) {
int value = (get(arNumbersFound, i, 0 /* = first column */)
if (i != 0) print ", " // print or do whatever you like with the numbers
print value ""
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Whoops it should be: int value = (get(arNumbersFound, i, 0 /* = first column */) int
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Extracting Integers from a string Mathias Mamsch - Thu Feb 07 04:08:53 EST 2013
Whoops it should be: int value = (get(arNumbersFound, i, 0 /* = first column */) int
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Ihre Eingabe sind sehr hilfreich. |
Re: Extracting Integers from a string Mathias Mamsch - Thu Feb 07 04:08:53 EST 2013
Whoops it should be: int value = (get(arNumbersFound, i, 0 /* = first column */) int
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Script is running for long and its stopping after sometime. Even if I see the o/p, the extracted values are getting printed against each Object ID. Attached you can find the DXL script. Attachments attachment_14939678_Update_ImplementedFeild_Module_New |
Re: Extracting Integers from a string SystemAdmin - Tue Feb 12 05:54:31 EST 2013 Would someone help me to resolve the issue so that extracted data is stored in the array for that partcular Object ID, so that I can compare the data and set the other attribute. |
Re: Extracting Integers from a string SystemAdmin - Tue Feb 26 01:25:08 EST 2013 DOORS is getting hanged if I run the DXL script attached to the post Attachments attachment_14952776_Update_ImplementedFeild_Module_New.c |
Re: Extracting Integers from a string SystemAdmin - Wed Mar 06 05:01:20 EST 2013
I notice your Arrays contain every found Reference for every object, specifically including duplicates. I notice 2 print statements per reference. print statements take expontially more time each time you print (the 1000th print is much slower than the 1st), and this may be your problem if you have 1000 or more objects. You could have a bufResults and change "print" to "bufResults +=", then do a single massive "print tempStringOf(bufResults)" at the bottom. -Louie Use an editor that lets you see tabs and spaces. |