Split a character string based on change of character: Difference between revisions

m
→‎{{header|Fortran}}: Crossreference.
(→‎{{header|AppleScript}}: Updated primitives)
m (→‎{{header|Fortran}}: Crossreference.)
Line 285:
This is F77 style, except for the <code>END SUBROUTINE SPLATTER</code> which would be just <code>END</code>, which for F90 is also allowable outside of the MODULE protocol. Linking the start/stop markers by giving the same name is helpful, especially when the compiler checks for this. The $ symbol at the end of a FORMAT code sequence is a common F77 extension, meaning "do not finish the line" so that a later output will follow on. This is acceptable to F90 and is less blather than adding the term <code>,ADVANCE = "NO"</code> inside a WRITE statement that would otherwise be required. Output is to I/O unit <code>6</code> which is the modern default for "standard output". The format code is <code>A</code> meaning "any number of characters" rather than <code>A1</code> for "one character" so as to accommodate not just the single character from TEXT but also the two characters of ", " for the splitter between sequences. Alas, there is no provision to change fount or colour for this, to facilitate the reader's attempts to parse the resulting list especially when the text includes commas or spaces of its own. By contrast, with quoted strings, the standard protocol is to double contained quotes.
 
An alternative method would be to prepare the entire output in a CHARACTER variable then write that, but this means answering the maddening question "how long is a piece of string?" for that variable, though later Fortran has arrangements whereby a text variable is resized to suit on every assignment, as in <code>TEMP = TEMP // more</code> - but this means repeatedly copying the text to the new manifestation of the variable. Still another approach would be to prepare an array of fingers to each split point (as in [[Phrase_reversals#Fortran]]) so that the final output would be a single WRITE using that array, and again, how big must the array be? At most, as big as the number of characters in TEXT. With F90, subroutines can declare arrays of a size determined on entry, with something like <code>INTEGER A(LEN(TEXT))</code>
 
If the problem were to be solved by writing a "main line" only, there would have to be a declaration of the text variable there but since a subroutine can receive a CHARACTER variable of any size (the actual size is passed as a secret parameter), this can be dodged.
1,220

edits