Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
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
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
Answer This question was answered by Richard Good, on Tuesday, August 16, 2005 6:40 PM

Answer:
Hopefully its as simple as I think!! see attached code
 11-Aug-2005 17:54
User is offline View Users Profile Print this message


Brian Jackson

Posts: 10
Joined: 2-Aug-2005

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?
Report this to a Moderator Report this to a Moderator
 11-Aug-2005 19:24
User is offline View Users Profile Print this message


Richard Good

Posts: 152
Joined: 22-Mar-2005

Answer Answer
Hopefully its as simple as I think!! see attached code

-------------------------
Regards,

Richard Good
Report this to a Moderator Report this to a Moderator
 11-Aug-2005 19:25
User is offline View Users Profile Print this message


Chris Jones

Posts: 177
Joined: 1-Jul-2005

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
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 1 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 1 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.