Extracting Integers from a string

Hi I am new to DXL. Can we possible to extact the integres from the string..
For example: Consider a string:
str = "0001,0002,003,0004.."
Can i extract the integer values 0001, 0002,0003.... to the variable of type int.
i.e. variabls a,b,c are type integer.
can we assign a = 0001, b = 0002 c = 0003 values extracted from the above string.
vinaykumarshankar - Fri Oct 05 01:48:55 EDT 2012

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

 


Maybe that helps, regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Extracting Integers from a string
SystemAdmin - Mon Feb 04 04:34:55 EST 2013

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

 


Maybe that helps, regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Hello Mathias,

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
Mathias Mamsch - Mon Feb 04 07:46:26 EST 2013

SystemAdmin - Mon Feb 04 04:34:55 EST 2013
Hello Mathias,

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

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)

 


Afterwards you can do what you want with those numbers. So where do you need help? Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: Extracting Integers from a string
SystemAdmin - Mon Feb 04 08:56:19 EST 2013

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)

 


Afterwards you can do what you want with those numbers. So where do you need help? Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Danke Mathias.
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:59:24 EST 2013

SystemAdmin - Mon Feb 04 08:56:19 EST 2013
Danke Mathias.
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?

I have used the regular expression
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
Mathias Mamsch - Mon Feb 04 15:22:23 EST 2013

SystemAdmin - Mon Feb 04 08:59:24 EST 2013
I have used the regular expression
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.

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

 


Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: Extracting Integers from a string
SystemAdmin - Tue Feb 05 06:11:29 EST 2013

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

 


Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Guten Tag Mathias.

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
llandale - Tue Feb 05 10:58:15 EST 2013

SystemAdmin - Tue Feb 05 06:11:29 EST 2013
Guten Tag Mathias.

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

pos=0 before BOTH while loops.

Re: Extracting Integers from a string
SystemAdmin - Wed Feb 06 01:37:35 EST 2013

llandale - Tue Feb 05 10:58:15 EST 2013
pos=0 before BOTH while loops.

I could extract the All the data.

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
Mathias Mamsch - Thu Feb 07 04:08:20 EST 2013

SystemAdmin - Wed Feb 06 01:37:35 EST 2013
I could extract the All the data.

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}

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 "" 
}

 


Regards, Mathias

 

 

 


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

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 "" 
}

 


Regards, Mathias

 

 

 


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
SystemAdmin - Thu Feb 07 05:07:49 EST 2013

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

 

 

vielen danke Herr Mathias.
Ihre Eingabe sind sehr hilfreich.

Re: Extracting Integers from a string
SystemAdmin - Tue Feb 12 05:54:31 EST 2013

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

 

 

Mathias, I have tried executing the script with your inputs.
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 26 01:25:08 EST 2013

SystemAdmin - Tue Feb 12 05:54:31 EST 2013
Mathias, I have tried executing the script with your inputs.
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.

With thte DXL script i have posted earlier, I could extract the numeric data, but the extracted numeric data is being listed for each and every object in the o/p panel.

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 - Wed Mar 06 05:01:20 EST 2013

SystemAdmin - Tue Feb 26 01:25:08 EST 2013
With thte DXL script i have posted earlier, I could extract the numeric data, but the extracted numeric data is being listed for each and every object in the o/p panel.

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.

Would anyone help me to resolve the error?

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
llandale - Thu Mar 07 14:05:31 EST 2013

SystemAdmin - Wed Mar 06 05:01:20 EST 2013
Would anyone help me to resolve the error?

DOORS is getting hanged if I run the DXL script attached to the post

I'm lazy and forgetful and not re-reading the thread, just looking at this code.
  • use "regexp2" not "regexp"
  • I think you need to "setempty" both Buffers at the top of the loop, in case your atts have null characters.
  • I notice you create the Arrays with 2 rows, but only use row #0.
  • "print value2" and the previous print need to move up into the loop.

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.