![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: writting to a text file Topic Summary: Created On: 23-Sep-2008 13:16 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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. |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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. |
|
![]() |
|
![]() |
|
Anurag, try:
string s = "RequirmentsEngineering" if(matches( "Engineering", s)) print s[match 0] " appears at " start(0) "" |
|
![]() |
|
![]() |
|
thanks for the tip ron.
|
|
![]() |
Telelogic DOORS
» DXL Exchange
»
writting to a text file
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.