![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: Selective string checking Topic Summary: Capturing certain parts of a string and converting to integer Created On: 11-Aug-2005 17:54 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() Answer: Hopefully its as simple as I think!! see attached code | |
![]() |
|
I have a text file that's read by a DXL script. I have no problem reading the contents of the text file line-by-line. When I read a line, by default, I store it as a string variable in my script. The contents of my text file looks similar to the following:
------------------------------ 3 5 23-4 7-4.2 8 ------------------------------ Like I mentioned, when I read the above text file, I store each line as a string type. But, in my actual DXL script, I need the integer conversion. Lines 1, 2, and 5 are easily converted to integer using the intOf() function. Lines 3 and 4 are difficult. For line 3, I need to capture the number 4. For line 4, I need to capture the number 2. For my purposes, I need to use if-then loops. My question is as follows: How do I code an if-then clause to check if a line from a text file is in a format like: if (x) { <some code> } else if (x-x) { <some code> } else if (x-x.x) { <some code> } where x is an integer Does this make sense? |
|
![]() |
|
![]() |
|
Hopefully its as simple as I think!! see attached code
------------------------- Regards, Richard Good |
|
![]() |
|
![]() |
|
You're going to want regular expressions. I think you'd want something like the following:
else if (x-x) Your regexp would be something like "-.*" -- a dash followed by any number of any character. But this would also give you the dash. There may be a way to find a certain string after a certain other string, but I don't have any idea how (I've never done much with regexes). else if (x-x.x) Would be similar but use a "\\." to find the dot--one slash to escape the dot in regular expression, and another to escape the escape in DXL. That makes sense, right? ![]() Look at the Regexp help in the DXL reference manual and play around with it some. Maybe someone that knows regexes like the back of their hand will have mercy on you! Chris Edit: Uhh, I got beat to the punch. Try Richard's way, it looks simple. Edited: 11-Aug-2005 at 19:26 by Chris Jones |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
Selective string checking
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.