- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have to create multiline string (for edit box).
CHARACTER(1000) M_STR
This is what I whant to have:
M_STR = "111 222 333"C.
Now:
S1 = "111"
S2 = "222"
S3 = "333"
Two operations below works wrong. I have "111 " as result.
M_STR = S1 // " "C // S2 // " "C // S3
WRITE(M_STR, *) S1, " "C, S2, " "C, S3
So, how can I concatinate several strings with between them??
Thanks!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
M_STR = TRIM(S1) // " "C // TRIM(S2) // " "C // TRIM(S3)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve_Lionel wrote:
I think you want:
M_STR = TRIM(S1) // " "C // TRIM(S2) // " "C // TRIM(S3)
Steve! Thanks, but I think problem is in "//" operation, not in spaces btrween strings :).
Thees two operations are not equals
1 M_STR = " 111 " // " "C // " 222 " // " "C
2 M_STR = " 111 222 "C
in first case the result is " 111 ".
WHY ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
CHARACTER(1000) M_STR
character*10 s1, s2, s3
!M_STR = "111 222 333"C.
!Now:
S1 = "111"
S2 = "222"
S3 = "333"
!Two operations below works wrong. I have "111 " as result.
M_STR = TRIM(S1) // " "C // TRIM(S2) // " "C // TRIM(S3)
write (*,*) trim(m_str)
WRITE(M_STR, *) TRIM(S1), " "C, TRIM(S2), " "C, TRIM(S3)
write (*,*) trim(m_str)
end
When I run this I get:
111
222
333
111
222
333
(The extra blank in the second example is due to your use of list-directed formatting in the WRITE to M_STR).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
dzuba,
How have you declared S1, S2, and S3 ?
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
First of all, you are making your strings c-strings by adding 'C' at the end.
This will cause the concatenated string to end at the first null character it finds, hence you are not getting the concatenated answer you want.
Secondly, if you want to use the ' ' way of generating carriage return and line feed, the whole character string in which they are used MUST be visible to the compiler at compile time, as that is when the ' c' is converted to the CHAR(13) and CHAR(10) characters that are carriage return and line feed. I discovered all this recently when trying to generate a multiline messge for use in MessageBox.
If you want new lines just use
character*2 crlf = CHAR(13)//CHAR(10)
STRING = STRING1//CRLF//STRING2//CRLF//STRING3//char(0)
And so on, where the component STRINGS are NOT terminated with CHAR(0) (the null terminator required at the end of the concatenated string to make it a C-string acceptable to windows functions like MessageBox). Also, TRIM the strings as Steve suggests before using them
You can also use internal WRITES as
WRITE(MESSAGE, '(a10,A2,A10,A2,A10)' ) string1,crlf,string2,crlf,string3//char(0)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'll comment that I like to make CLRF a PARAMETER.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
anthonyrichards,
I did't noticed that " "C is equals to
char(10)//char(13)//char(0)
So, the string was wrapped after first char(0) when I passed it to rhe edit box.
Tank you.
![](/skins/images/2F496A9BF2E73260E2FDFDBCABF91248/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page