Recipe 5.19. Double-Spacing a String


Problem

You want to double-space a string comprised of multiple lines of text separated by newlines.

Solution

Use the String object's Replace() method to replace all vbNewLines with two vbNewLines.

Discussion

The Replace() method provides an easy solution to this problem. Simply replace each occurrence of a vbNewLine separating the lines of text with a double vbNewLine:

 content = content.Replace(vbNewLine, vbNewLine & vbNewLine) 

Figures 5-20 and 5-21 show a multiline example string before and after this replacement.

Figure 5-20. A string comprised of five lines of single-spaced text


Figure 5-21. The same string, double spaced


See Also

Recipe 5.16 shows how to replace specific substrings within a larger string.




Visual Basic 2005 Cookbook(c) Solutions for VB 2005 Programmers
Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (OReilly))
ISBN: 0596101775
EAN: 2147483647
Year: 2006
Pages: 400

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net