Felix
Felix

Reputation: 219

How to keep all the spaces in a string?

When using C to write a string of html to a client socket,the length of the spaces in the string are all truncated to one when shown in a web page.How to keep all the spaces?

Upvotes: 1

Views: 8150

Answers (4)

Martin
Martin

Reputation: 1822

Replace spaces with

 

in the output - special character for space

Upvotes: 2

Alfie
Alfie

Reputation: 2350

Replace the spaces with   (the HTML escape sequence for a space). Whitespace is ignored by HTML interpreters, so any markup with more than 1 space next to each other will be treated as a single space.

Also, as @alk suggested, you can also surround your string with <pre></pre>: Text in a element is displayed in a fixed-width font (usually Courier), and it preserves both spaces and line breaks.

Upvotes: 0

Douglas
Douglas

Reputation: 37761

To preserve spaces in the html when shown in a web browser, use the white-space: pre CSS style.

Upvotes: 4

Shardj
Shardj

Reputation: 1969

As far as I can see "a b" is the same as "a b" but I can see what you're trying to say. what you could do is remove all the spaces before posting and keep an array of their locations. Then use JavaScript at the other end to add back in the spaces.

More recommended is using the answer already given but I thought I would put something different out

Upvotes: 0

Related Questions