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: How to get an Integer value of a string?
Topic Summary:
Created On: 5-Jul-2004 13:07
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.
 5-Jul-2004 13:45
User is offline View Users Profile Print this message


Dirk Plaschke

Posts: 103
Joined: 17-Sep-2002

Hi, Karsten.

You can try "int i = intOf("5")", for example.
If you would have the real part of a number, try "int r = realOf("3,14")".

regards,
dirk.

-------------------------
Dirk Plaschke
Report this to a Moderator Report this to a Moderator
 5-Jul-2004 13:48
User is offline View Users Profile Print this message


Alexander Lundh

Posts: 8
Joined: 28-Jun-2004

EDIT: oups, didnt think intOf worked on strings, no need for the stoi/atoi function.
(sorry)

It is, here's a little example
(not sure if there are any math functions like power(x,y) in DXL, so this is a bit "ugly")

--------------------
int stoi(string x){
int i
int power=1
int result=0

//since I didnt know any mathFunctions like power in DXL, I made an ugly loop
for i in 1:length x do power=power*10

//main loop, rather self-explaining
for(i=0;i<length x;i++){
power = power/10
result = result + power*intOf(x[i:i])
}
return result
}
--------------------

stoi = string-to-integer
the reason that I use 2 loops that work with power is that the first loop is of reverse order of the last;
you might want a few controlls that the letters really are digits in the loop.
Im sure this can be written in an easier way, this was just ... on top of my head.

Hope it helps

Alex


Edited: 5-Jul-2004 at 13:52 by Alexander Lundh
Report this to a Moderator Report this to a Moderator
 5-Jul-2004 14:36
User is offline View Users Profile Print this message


Dirk Plaschke

Posts: 103
Joined: 17-Sep-2002

Hi, Alex.

For the 'ugly loop', you can use "power = intOf(pow( 10.0, realOf(length(x)-1)))".

dirk.

-------------------------
Dirk Plaschke
Report this to a Moderator Report this to a Moderator
 6-Jul-2004 04:44
User is offline View Users Profile Print this message


Chun Ho

Posts: 6
Joined: 21-May-2004

Just more info:

intOf() will throw an error if you pass it a non-numeric string. You could test the string with isValidInt() first.

Some Math functions in DXL:
sin
cos
tan
exp
log
pow
sqrt
random


Refer to the DXL Reference Manual (under DOORS Help menu) for more information.

Thanks
---------
chun.ho(at)motorola.com
Report this to a Moderator Report this to a Moderator
 7-Jul-2004 17:29
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

//***************
bool fStringToInt(string InString, int &OutInt)
{ // Convert the InString to a valid Integer. Return whether it worked.
// Improper or null Strings return False and Zero
OutInt = 0
if (null InString) return(false)
if (!isValidInt(InString)) return(false)
OutInt = intOf(InString)
return(true)
} // end fStringToInt()
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.