> In C you can write something like this
>
> #define something = "döaslkdasö" \
> "djalkjddlasdj" \
> "asdölasköla" \
> "ädadassdlö"
Is this legal C? Wouldn't you need some sort of concatenation operator
between each string?
> to prevent long definitions in one big line, not writing a long clause
> like:
[quoted text clipped - 10 lines]
> " loooooooooong sentence or value " +
> "</tag>"
This would be legal Java except for the fact that "<myKey" is not a
legal identifier. If you rename it "myKey", it should work, assuming myKey
can be assigned a string.
However, maybe I'm completely misunderstanding you, because the subject
of this post talks about *reading* XML, but you seem be *writing* strings.
- Oliver
Roedy Green - 02 Feb 2006 21:13 GMT
>> #define something = "döaslkdasö" \
>> "djalkjddlasdj" \
[quoted text clipped - 3 lines]
> Is this legal C? Wouldn't you need some sort of concatenation operator
>between each string?
in C it is as if the line breaks were not there. So you don't need an
operator.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Oliver Wong - 02 Feb 2006 22:12 GMT
>>> #define something = "döaslkdasö" \
>>> "djalkjddlasdj" \
[quoted text clipped - 6 lines]
> in C it is as if the line breaks were not there. So you don't need an
> operator.
I'm aware of the usage of \ to "escape" line breaks, but wouldn't code
like:
<C code>
something = "a" \
"b"
</C code>
be seen by the compiler (after the pre-processor has had its way with
it) as:
<C code>
something = "a" "b"
</C code>
Or does the \ actually remove the white space indendation and pairs of
quotation marks as well?
- Oliver
~Glynne - 03 Feb 2006 20:26 GMT
> >>> #define something = "döaslkdasö" \
> >>> "djalkjddlasdj" \
[quoted text clipped - 21 lines]
> something = "a" "b"
> </C code>
Yes.
> Or does the \ actually remove the white space indendation and pairs of
> quotation marks as well?
The C compiler concatenates adjacent string literals into a single
string literal....but this "trick" will not work at run time, i.e. with
string variables.
~Glynne
>I mean something like this:
>
><myKey = "<tag> this is a veeeeeeeeery " +
> " loooooooooong sentence or value " +
> "</tag>"
I think in XML \n is treated as if it were space. At least that is how
its relatives work. That still does not give you a way of breaking up
a long string without embedded spaces.
One practical way of handling the situation would be on parsing the
file to compact the strings to get to get rid of junk whitespace
introduced through transport with XML.
/**
* Remove all spaces from a String. see also condense .
*
* @param s
* String to strip of blanks.
* @return String with all blanks, lead/trail/embedded removed.
*/
public static String squish ( String s )
{
if ( s == null )
{
return null;
}
s = s.trim();
if ( s.indexOf( ' ' ) < 0 )
{
return s;
}
int len = s.length();
StringBuilder b = new StringBuilder( len - 1 );
for ( int i = 0; i < len; i++ )
{
char c = s.charAt( i );
if ( c != ' ' )
{
b.append( c );
}
} // end for
return b.toString();
} // end squish

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
JimmyB - 03 Feb 2006 17:32 GMT
Thanks Roedy!
A good point that gives me new ideas.
Cheers!
>>I mean something like this:
>>
[quoted text clipped - 41 lines]
> return b.toString();
> } // end squish