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: writting to a text file
Topic Summary:
Created On: 23-Sep-2008 13:16
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.
 23-Sep-2008 13:16
User is offline View Users Profile Print this message


Anurag Chukka

Posts: 13
Joined: 6-Sep-2008

hi
i want to write a string into a text file which has been selected by the user through
the DBE element fileName.

the problem is the fileName returns the path of the selected file as eg: d:\test.txt.
and when i assign it to an output stream and try to write some string into it, it is not working.

eg:

Stream output
output=get(DBE ) // this returns the path as d:\test.txt
output<< "some string"

ive observed, this is working only when the path of the text file is either 1. d:\\test.txt or d:/test.txt

ive tried to replace the backslash character with a forward slash after collecting the path in a string. but i couldnt do that either.
is there any way to work around this problem.

i would really appreciate any help..
thanx
Report this to a Moderator Report this to a Moderator
 23-Sep-2008 13:28
User is offline View Users Profile Print this message


Scott Boisvert

Posts: 348
Joined: 14-Apr-2006

You need to use the write function when opening a Stream to write to a file.

Try this:

Stream output
output = write (get (DBE))
output << "some string"

-------------------------
Scott Boisvert
Engineering Tools Administrator
L-3 Communications - Avionics Systems
scott.boisvert@l-3com.com
Report this to a Moderator Report this to a Moderator
 23-Sep-2008 13:31
User is offline View Users Profile Print this message


Peter Albert

Posts: 232
Joined: 30-Dec-2005

Your observation is correct, the path separator must either be double backslash or forward slash. One error in your code fragment is the missing 'write' or 'append' before 'get(DBE)', but I guess this is correct in your original code. What is your problem with replacing the backslash? Can't you get the replacing to work, or does the Stream still not work?

Peter

Edited: 23-Sep-2008 at 13:31 by Peter Albert
Report this to a Moderator Report this to a Moderator
 23-Sep-2008 13:42
User is offline View Users Profile Print this message


Anurag Chukka

Posts: 13
Joined: 6-Sep-2008

thanks for the reply peter. as you said ive used write in my original code. it was a typo.

ive used:

Stream output
output = write (get (DBE))
output << "some string"

the get(DBE) returns something like: d:\myfile.txt
now as u said the path separator has to be replaced by a forward slash, or a double back slash.

ive tried to do that. but i didnt get the replacing work.

ive tried as follows:

string path= d:\myfile.txt
string temp=""
int i=0
while(i<length(path))
{
if(path=='\\')
temp=temp "/"
else
temp=temp path[i:i]
}

//im trying to collect my required path in the variable temp.
Report this to a Moderator Report this to a Moderator
 23-Sep-2008 13:52
User is offline View Users Profile Print this message


Scott Boisvert

Posts: 348
Joined: 14-Apr-2006

I don't think there is a need to replace the backslash. I do this all the time. What you may need to do is assign the data from the DBE to a string or buffer first. This is what I do in my scripts.

Buffer b = create (1)
b += get (DBE)

Stream output = write (tempStringOf (b))

output << "Some string"

delete (b)

Or...

string s = get (DBE)

Stream output = write (s)

output << "Some string"

I prefer using the buffer even though it's a few extra lines of code, due to DXL's issue with strings and not releasing its memory. At least with a buffer you can delete it....

-------------------------
Scott Boisvert
Engineering Tools Administrator
L-3 Communications - Avionics Systems
scott.boisvert@l-3com.com
Report this to a Moderator Report this to a Moderator
 23-Sep-2008 14:13
User is offline View Users Profile Print this message


Anurag Chukka

Posts: 13
Joined: 6-Sep-2008

hi scott,

i am not sure if there is no need to replace the backslash. this is first time im trying to write to a text file.

ive tried with the following codes:
but in vain. it didnt write the string in the target text file.

DB main = create ""
DBE f = fileName(main, "Text File"," ", "*.txt", "text files", false)
string s
Buffer b=create(1)
void printIt( DB main ){
b+= get f
Stream output=write(tempStringOf(b))
output<<"some string"

}
apply ( main, "Print", printIt)
show main


and also with strings as follows:

DB main = create "sdf"
DBE f = fileName(main, "Text File"," ", "*.txt", "text files", false)
string s
void printIt( DB main ){
s= get f
Stream output=write(s)
output<<"some string"
}
apply ( main, "Print", printIt)
show main

Both of them didnt work. i mean teh specified string was written to the text file
Report this to a Moderator Report this to a Moderator
 23-Sep-2008 14:48
User is offline View Users Profile Print this message


Peter Albert

Posts: 232
Joined: 30-Dec-2005

Scott was perfectly right, however, you were still lacking the closure of the stream and the deletion of the Buffer. Attached is a version which works fine.

Peter
Report this to a Moderator Report this to a Moderator
 23-Sep-2008 15:24
User is offline View Users Profile Print this message


Anurag Chukka

Posts: 13
Joined: 6-Sep-2008

thanks for pointing the error peter. it is working fine now.

Just have one more question.

i want to know if a string eg. "RequiremntsEngineering" contains a string eg:"Engineering". Ive tried to use buffers and the function "contains" but contains works fine only if the string is preceded by a non-alpha numeric character.

here in my case the string im searching for is not preceded by a non alpha numeric character.

can you provide me with some idea. should i have to work with regexpressions.
Report this to a Moderator Report this to a Moderator
 23-Sep-2008 15:46
User is offline View Users Profile Print this message


ron lewis

Posts: 650
Joined: 20-Sep-2004

Anurag, try:

string s = "RequirmentsEngineering"
if(matches( "Engineering", s)) print s[match 0] " appears at " start(0) ""
Report this to a Moderator Report this to a Moderator
 23-Sep-2008 15:57
User is offline View Users Profile Print this message


Anurag Chukka

Posts: 13
Joined: 6-Sep-2008

thanks for the tip ron.
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.