VB.NET || Word Wrap – How To Split A String Text Into lines With Maximum Length
The following is a module with functions which demonstrates how to split text into multiple lines using VB.NET.
The following function is an extension method, which takes a string, and splits it into multiple lines (array indices) of a specified length.
An optional boolean parameter specifies whether this function should break up long individual words to fit as many characters as possible on a line.
With this option enabled, if a word is too long to fit on a line, the word is broken up to fit as many characters as possible up to the maximum length on the current line, and the remaining characters gets moved to the next line (the next array index).
Note: Don’t forget to include the ‘Utils Namespace‘ before running the examples!
1. Word Wrap – Don’t Break Words
The example below demonstrates the use of ‘Utils.WordWrap‘ to split a string into multiple lines.
In this example, individual words are not broken up. They are simply moved onto the next line (if necessary).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
' Word Wrap - Don't Break Words Imports Utils ' Limit string text to 40 characters per line Dim text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus faucibus venenatis justo, placerat maximus tortor dictum non. Curabitur efficitur pulvinar arcu, id vehicula nisi commodo in. Interdum et malesuada fames ac ante ipsum primis in faucibus. Vivamus consectetur ut orci scelerisque fringilla. Sed id nisl ac nunc congue suscipit at sollicitudin elit. Nullam tempus tortor sit amet molestie rutrum. Sed a sollicitudin magna, eget vulputate tortor. Proin ut sodales orci, a iaculis ipsum.Ut nec odio risus. Vivamus viverra metus turpis. Pellentesque lacinia lacinia tempus. Suspendisse in justo eget orci porttitor ornare vitae nec tortor. Donec dolor odio, dapibus non sodales quis, volutpat a turpis. Curabitur eget fermentum ante. Donec pulvinar nulla non ante mattis aliquam.Aenean vulputate, ligula sit amet laoreet porttitor, magna justo pellentesque diam, id tempus eros orci ut arcu. Praesent et finibus ipsum. Mauris luctus, metus vel sagittis pharetra, felis odio placerat felis, et ullamcorper neque turpis eget tellus. Maecenas vel imperdiet augue. Morbi imperdiet diam ac enim cursus venenatis. Donec eros turpis, pharetra a aliquet sed, vehicula sed libero. Donec efficitur volutpat ex, in euismod dolor tristique at. Quisque a nisi ultricies libero lacinia fringilla nec vel tortor.Aenean id felis et quam lacinia ornare. Curabitur blandit, arcu eget ultricies pulvinar, neque lectus ultrices mauris, vitae feugiat mauris diam id tellus. Vestibulum finibus cursus dui et feugiat. Sed vitae sagittis lorem. Duis suscipit sollicitudin est tempor efficitur. Morbi eget fringilla massa. Integer ullamcorper, ligula congue consequat sodales, dolor eros pretium augue, in luctus enim massa quis est. Fusce cursus ac ipsum quis aliquet. Curabitur pharetra lectus non suscipit scelerisque. Pellentesque vitae scelerisque tellus. Donec sit amet ligula felis. Donec ac hendrerit magna, sed pharetra diam. Morbi gravida felis finibus sodales suscipit. In hac habitasse platea dictumst.Curabitur purus erat, tincidunt vel tincidunt et, fermentum eget dui. Fusce eu justo vel massa ultrices lacinia sit amet quis augue. Nunc fringilla justo quis felis fringilla, at rutrum justo venenatis. Ut ullamcorper gravida finibus. Donec fermentum varius metus sit amet porttitor. Sed at auctor velit. Quisque et urna metus. Donec ut mi vel turpis dignissim pulvinar. Curabitur massa leo, interdum ac urna id, dictum pellentesque nunc. Ut dolor justo, vehicula quis porta in, laoreet eget augue. this is a test pneumonoultramicroscopicsilicovolcanoconiosis" Dim maxCharacters = 40 Dim result = text.WordWrap(maxCharacters) For Each line In result Display($"Length: {line.Length} - {line}") Next ' expected output: ' Length: 39 - Lorem ipsum dolor sit amet, consectetur ' Length: 35 - adipiscing elit. Phasellus faucibus ' Length: 40 - venenatis justo, placerat maximus tortor ' Length: 40 - dictum non. Curabitur efficitur pulvinar ' Length: 34 - arcu, id vehicula nisi commodo in. ' Length: 35 - Interdum et malesuada fames ac ante ' Length: 33 - ipsum primis in faucibus. Vivamus ' Length: 31 - consectetur ut orci scelerisque ' Length: 37 - fringilla. Sed id nisl ac nunc congue ' Length: 37 - suscipit at sollicitudin elit. Nullam ' Length: 39 - tempus tortor sit amet molestie rutrum. ' Length: 40 - Sed a sollicitudin magna, eget vulputate ' Length: 40 - tortor. Proin ut sodales orci, a iaculis ' Length: 40 - ipsum.Ut nec odio risus. Vivamus viverra ' Length: 34 - metus turpis. Pellentesque lacinia ' Length: 36 - lacinia tempus. Suspendisse in justo ' Length: 36 - eget orci porttitor ornare vitae nec ' Length: 37 - tortor. Donec dolor odio, dapibus non ' Length: 32 - sodales quis, volutpat a turpis. ' Length: 36 - Curabitur eget fermentum ante. Donec ' Length: 30 - pulvinar nulla non ante mattis ' Length: 36 - aliquam.Aenean vulputate, ligula sit ' Length: 35 - amet laoreet porttitor, magna justo ' Length: 38 - pellentesque diam, id tempus eros orci ' Length: 35 - ut arcu. Praesent et finibus ipsum. ' Length: 33 - Mauris luctus, metus vel sagittis ' Length: 39 - pharetra, felis odio placerat felis, et ' Length: 37 - ullamcorper neque turpis eget tellus. ' Length: 35 - Maecenas vel imperdiet augue. Morbi ' Length: 40 - imperdiet diam ac enim cursus venenatis. ' Length: 37 - Donec eros turpis, pharetra a aliquet ' Length: 31 - sed, vehicula sed libero. Donec ' Length: 39 - efficitur volutpat ex, in euismod dolor ' Length: 38 - tristique at. Quisque a nisi ultricies ' Length: 32 - libero lacinia fringilla nec vel ' Length: 38 - tortor.Aenean id felis et quam lacinia ' Length: 36 - ornare. Curabitur blandit, arcu eget ' Length: 32 - ultricies pulvinar, neque lectus ' Length: 37 - ultrices mauris, vitae feugiat mauris ' Length: 34 - diam id tellus. Vestibulum finibus ' Length: 32 - cursus dui et feugiat. Sed vitae ' Length: 29 - sagittis lorem. Duis suscipit ' Length: 40 - sollicitudin est tempor efficitur. Morbi ' Length: 29 - eget fringilla massa. Integer ' Length: 36 - ullamcorper, ligula congue consequat ' Length: 37 - sodales, dolor eros pretium augue, in ' Length: 40 - luctus enim massa quis est. Fusce cursus ' Length: 32 - ac ipsum quis aliquet. Curabitur ' Length: 28 - pharetra lectus non suscipit ' Length: 31 - scelerisque. Pellentesque vitae ' Length: 34 - scelerisque tellus. Donec sit amet ' Length: 39 - ligula felis. Donec ac hendrerit magna, ' Length: 38 - sed pharetra diam. Morbi gravida felis ' Length: 32 - finibus sodales suscipit. In hac ' Length: 35 - habitasse platea dictumst.Curabitur ' Length: 39 - purus erat, tincidunt vel tincidunt et, ' Length: 38 - fermentum eget dui. Fusce eu justo vel ' Length: 36 - massa ultrices lacinia sit amet quis ' Length: 38 - augue. Nunc fringilla justo quis felis ' Length: 40 - fringilla, at rutrum justo venenatis. Ut ' Length: 34 - ullamcorper gravida finibus. Donec ' Length: 31 - fermentum varius metus sit amet ' Length: 39 - porttitor. Sed at auctor velit. Quisque ' Length: 37 - et urna metus. Donec ut mi vel turpis ' Length: 40 - dignissim pulvinar. Curabitur massa leo, ' Length: 40 - interdum ac urna id, dictum pellentesque ' Length: 35 - nunc. Ut dolor justo, vehicula quis ' Length: 39 - porta in, laoreet eget augue. this is a ' Length: 4 - test ' Length: 45 - pneumonoultramicroscopicsilicovolcanoconiosis |
2. Word Wrap – Break Words
The example below demonstrates the use of ‘Utils.WordWrap‘ to split a string into multiple lines.
In this example, individual words are broken up and moved onto the next line (if necessary), with the default hyphen character used, which is a dash (‘-‘).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
' Word Wrap - Break Words Imports Utils ' Limit string text to 40 characters per line Dim text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus faucibus venenatis justo, placerat maximus tortor dictum non. Curabitur efficitur pulvinar arcu, id vehicula nisi commodo in. Interdum et malesuada fames ac ante ipsum primis in faucibus. Vivamus consectetur ut orci scelerisque fringilla. Sed id nisl ac nunc congue suscipit at sollicitudin elit. Nullam tempus tortor sit amet molestie rutrum. Sed a sollicitudin magna, eget vulputate tortor. Proin ut sodales orci, a iaculis ipsum.Ut nec odio risus. Vivamus viverra metus turpis. Pellentesque lacinia lacinia tempus. Suspendisse in justo eget orci porttitor ornare vitae nec tortor. Donec dolor odio, dapibus non sodales quis, volutpat a turpis. Curabitur eget fermentum ante. Donec pulvinar nulla non ante mattis aliquam.Aenean vulputate, ligula sit amet laoreet porttitor, magna justo pellentesque diam, id tempus eros orci ut arcu. Praesent et finibus ipsum. Mauris luctus, metus vel sagittis pharetra, felis odio placerat felis, et ullamcorper neque turpis eget tellus. Maecenas vel imperdiet augue. Morbi imperdiet diam ac enim cursus venenatis. Donec eros turpis, pharetra a aliquet sed, vehicula sed libero. Donec efficitur volutpat ex, in euismod dolor tristique at. Quisque a nisi ultricies libero lacinia fringilla nec vel tortor.Aenean id felis et quam lacinia ornare. Curabitur blandit, arcu eget ultricies pulvinar, neque lectus ultrices mauris, vitae feugiat mauris diam id tellus. Vestibulum finibus cursus dui et feugiat. Sed vitae sagittis lorem. Duis suscipit sollicitudin est tempor efficitur. Morbi eget fringilla massa. Integer ullamcorper, ligula congue consequat sodales, dolor eros pretium augue, in luctus enim massa quis est. Fusce cursus ac ipsum quis aliquet. Curabitur pharetra lectus non suscipit scelerisque. Pellentesque vitae scelerisque tellus. Donec sit amet ligula felis. Donec ac hendrerit magna, sed pharetra diam. Morbi gravida felis finibus sodales suscipit. In hac habitasse platea dictumst.Curabitur purus erat, tincidunt vel tincidunt et, fermentum eget dui. Fusce eu justo vel massa ultrices lacinia sit amet quis augue. Nunc fringilla justo quis felis fringilla, at rutrum justo venenatis. Ut ullamcorper gravida finibus. Donec fermentum varius metus sit amet porttitor. Sed at auctor velit. Quisque et urna metus. Donec ut mi vel turpis dignissim pulvinar. Curabitur massa leo, interdum ac urna id, dictum pellentesque nunc. Ut dolor justo, vehicula quis porta in, laoreet eget augue. this is a test pneumonoultramicroscopicsilicovolcanoconiosis" Dim maxCharacters = 40 Dim result = text.WordWrap(maxCharacters, True) For Each line In result Display($"Length: {line.Length} - {line}") Next ' expected output: ' Length: 39 - Lorem ipsum dolor sit amet, consectetur ' Length: 40 - adipiscing elit. Phasellus faucibus ven- ' Length: 40 - enatis justo, placerat maximus tortor d- ' Length: 39 - ictum non. Curabitur efficitur pulvinar ' Length: 40 - arcu, id vehicula nisi commodo in. Inte- ' Length: 40 - rdum et malesuada fames ac ante ipsum p- ' Length: 38 - rimis in faucibus. Vivamus consectetur ' Length: 40 - ut orci scelerisque fringilla. Sed id n- ' Length: 40 - isl ac nunc congue suscipit at sollicit- ' Length: 40 - udin elit. Nullam tempus tortor sit amet ' Length: 40 - molestie rutrum. Sed a sollicitudin mag- ' Length: 40 - na, eget vulputate tortor. Proin ut sod- ' Length: 38 - ales orci, a iaculis ipsum.Ut nec odio ' Length: 40 - risus. Vivamus viverra metus turpis. Pe- ' Length: 40 - llentesque lacinia lacinia tempus. Susp- ' Length: 40 - endisse in justo eget orci porttitor or- ' Length: 40 - nare vitae nec tortor. Donec dolor odio, ' Length: 40 - dapibus non sodales quis, volutpat a tu- ' Length: 40 - rpis. Curabitur eget fermentum ante. Do- ' Length: 40 - nec pulvinar nulla non ante mattis aliq- ' Length: 40 - uam.Aenean vulputate, ligula sit amet l- ' Length: 40 - aoreet porttitor, magna justo pellentes- ' Length: 38 - que diam, id tempus eros orci ut arcu. ' Length: 40 - Praesent et finibus ipsum. Mauris luctu- ' Length: 40 - s, metus vel sagittis pharetra, felis o- ' Length: 40 - dio placerat felis, et ullamcorper neque ' Length: 40 - turpis eget tellus. Maecenas vel imperd- ' Length: 39 - iet augue. Morbi imperdiet diam ac enim ' Length: 40 - cursus venenatis. Donec eros turpis, ph- ' Length: 40 - aretra a aliquet sed, vehicula sed libe- ' Length: 40 - ro. Donec efficitur volutpat ex, in eui- ' Length: 39 - smod dolor tristique at. Quisque a nisi ' Length: 38 - ultricies libero lacinia fringilla nec ' Length: 40 - vel tortor.Aenean id felis et quam laci- ' Length: 40 - nia ornare. Curabitur blandit, arcu eget ' Length: 40 - ultricies pulvinar, neque lectus ultric- ' Length: 39 - es mauris, vitae feugiat mauris diam id ' Length: 40 - tellus. Vestibulum finibus cursus dui et ' Length: 39 - feugiat. Sed vitae sagittis lorem. Duis ' Length: 40 - suscipit sollicitudin est tempor effici- ' Length: 40 - tur. Morbi eget fringilla massa. Integer ' Length: 40 - ullamcorper, ligula congue consequat so- ' Length: 40 - dales, dolor eros pretium augue, in luc- ' Length: 40 - tus enim massa quis est. Fusce cursus ac ' Length: 38 - ipsum quis aliquet. Curabitur pharetra ' Length: 40 - lectus non suscipit scelerisque. Pellen- ' Length: 38 - tesque vitae scelerisque tellus. Donec ' Length: 40 - sit amet ligula felis. Donec ac hendrer- ' Length: 40 - it magna, sed pharetra diam. Morbi grav- ' Length: 38 - ida felis finibus sodales suscipit. In ' Length: 39 - hac habitasse platea dictumst.Curabitur ' Length: 39 - purus erat, tincidunt vel tincidunt et, ' Length: 38 - fermentum eget dui. Fusce eu justo vel ' Length: 40 - massa ultrices lacinia sit amet quis au- ' Length: 40 - gue. Nunc fringilla justo quis felis fr- ' Length: 38 - ingilla, at rutrum justo venenatis. Ut ' Length: 40 - ullamcorper gravida finibus. Donec ferm- ' Length: 38 - entum varius metus sit amet porttitor. ' Length: 40 - Sed at auctor velit. Quisque et urna me- ' Length: 40 - tus. Donec ut mi vel turpis dignissim p- ' Length: 38 - ulvinar. Curabitur massa leo, interdum ' Length: 40 - ac urna id, dictum pellentesque nunc. Ut ' Length: 40 - dolor justo, vehicula quis porta in, la- ' Length: 40 - oreet eget augue. this is a test pneumo- ' Length: 39 - noultramicroscopicsilicovolcanoconiosis |
3. Utils Namespace
The following is the Utils Namespace. Include this in your project to start using!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
' ============================================================================ ' Author: Kenneth Perkins ' Date: Nov 3, 2020 ' Taken From: http://programmingnotes.org/ ' File: Utils.vb ' Description: Handles general utility functions ' ============================================================================ Option Strict On Option Explicit On Namespace Global.Utils Public Module modUtils ''' <summary> ''' Takes in a string and splits it into multiple lines (array indices) ''' of a specified length. If a word is too long to fit on a line, ''' the word gets moved to the next line (the next array index) ''' </summary> ''' <param name="text">The text to word wrap</param> ''' <param name="maxCharactersPerLine">The maximum characters per ''' line</param> ''' <param name="breakWords">Determine if words should fit as many as ''' possible on current line, with remaining broken up to the next line</param> ''' <param name="hyphenChar">The character to use at the end of the line ''' as a hyphen when breaking up words</param> ''' <param name="hyphenatedWordMinLength">The minimum length of the ''' hyphenated word after it is broken up. A word will not be hyphenated ''' unless it meets this minimum length after it is broken up</param> ''' <returns>A list of strings that contains each line limited by ''' the specified length</returns> <Runtime.CompilerServices.Extension()> Public Function WordWrap(text As String, maxCharactersPerLine As Integer, Optional breakWords As Boolean = False, Optional hyphenChar As Char? = "-"c, Optional hyphenatedWordMinLength As Integer = 1) As List(Of String) If breakWords AndAlso hyphenatedWordMinLength >= maxCharactersPerLine Then Throw New System.InvalidOperationException($"Unable to fit the value of '{NameOf(hyphenatedWordMinLength)}' ({hyphenatedWordMinLength}) with '{NameOf(maxCharactersPerLine)}' ({maxCharactersPerLine}). Either increase the value of '{NameOf(maxCharactersPerLine)}' or decrease the value of '{NameOf(hyphenatedWordMinLength)}'") End If text = text.Trim() Dim result = New List(Of String)() If text.Length <= maxCharactersPerLine Then result.Add(text) Else Dim words = text.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries) Dim leftOver = String.Empty Dim wordIndex As Integer = 0 While wordIndex < words.Length OrElse Not String.IsNullOrWhiteSpace(leftOver) Dim currentResultLineIndex = result.Count - 1 Dim currentResultLineLength = If(currentResultLineIndex > -1, result(currentResultLineIndex).Length, 0) ' Start string with left over text from previous word Dim addition = String.Empty If Not String.IsNullOrWhiteSpace(leftOver) Then If currentResultLineLength > 0 _ AndAlso currentResultLineLength < maxCharactersPerLine _ AndAlso Not leftOver.StartsWith(" ") Then addition &= " " End If addition &= leftOver End If ' Add current word to string If wordIndex < words.Length Then Dim word = words(wordIndex).Trim() If currentResultLineLength > 0 AndAlso Not addition.EndsWith(" ") Then addition &= " " End If addition &= word End If If breakWords Then ' Determine how many characters to take from the current addition Dim remainingLineLength = maxCharactersPerLine - currentResultLineLength Dim charactersToAddLength = Math.Min((If(remainingLineLength > 0, remainingLineLength, maxCharactersPerLine)), addition.Length) ' Include hyphen if word will be broken up If charactersToAddLength > 1 AndAlso charactersToAddLength < addition.Length Then Dim slice = addition.Substring(0, charactersToAddLength) If Not String.IsNullOrWhiteSpace(slice) Then If Not hyphenChar.HasValue OrElse Not slice(charactersToAddLength - 1) = hyphenChar Then ' Determine the length of the hyphenated word Dim hyphenatedWordLength = 0 Dim hyphenInsertIndexStart = charactersToAddLength - 1 While hyphenInsertIndexStart >= 0 _ AndAlso Not Char.IsWhiteSpace(slice(hyphenInsertIndexStart)) hyphenatedWordLength += 1 hyphenInsertIndexStart -= 1 End While ' Subtract the hypenated character from the result If hyphenChar.HasValue Then hyphenatedWordLength -= 1 End If If hyphenatedWordLength >= hyphenatedWordMinLength Then addition = addition.Insert(charactersToAddLength - 1, If(hyphenChar.HasValue, hyphenChar.ToString(), String.Empty)) ElseIf hyphenInsertIndexStart >= 0 AndAlso (Not hyphenChar.HasValue OrElse Not addition(hyphenInsertIndexStart) = hyphenChar) Then addition = addition.Insert(hyphenInsertIndexStart, New String(" "c, hyphenatedWordMinLength)) End If End If End If End If currentResultLineLength += charactersToAddLength ' Save excess characters from current addition for the next line leftOver = If(charactersToAddLength < addition.Length, addition.Substring(charactersToAddLength), String.Empty) ' Only take the specified characters from the string addition = addition.Substring(0, charactersToAddLength) Else currentResultLineLength += addition.Length End If ' Add or append words to result If result.Count < 1 OrElse currentResultLineLength > maxCharactersPerLine Then ' Start new line addition = addition.Trim() result.Add(addition) Else ' Append existing line result(currentResultLineIndex) &= addition End If wordIndex += 1 End While End If ' Remove excess whitespace For index = 0 To result.Count - 1 result(index) = result(index).Trim() Next Return result End Function End Module End Namespace ' http://programmingnotes.org/ |
4. More Examples
Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
' ============================================================================ ' Author: Kenneth Perkins ' Date: Nov 3, 2020 ' Taken From: http://programmingnotes.org/ ' File: Program.vb ' Description: The following demonstrates the use of the Utils Namespace ' ============================================================================ Option Strict On Option Explicit On Imports System Imports Utils Public Module Program Sub Main(args As String()) Try ' Limit string text to 40 characters per line Dim text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus faucibus venenatis justo, placerat maximus tortor dictum non. Curabitur efficitur pulvinar arcu, id vehicula nisi commodo in. Interdum et malesuada fames ac ante ipsum primis in faucibus. Vivamus consectetur ut orci scelerisque fringilla. Sed id nisl ac nunc congue suscipit at sollicitudin elit. Nullam tempus tortor sit amet molestie rutrum. Sed a sollicitudin magna, eget vulputate tortor. Proin ut sodales orci, a iaculis ipsum.Ut nec odio risus. Vivamus viverra metus turpis. Pellentesque lacinia lacinia tempus. Suspendisse in justo eget orci porttitor ornare vitae nec tortor. Donec dolor odio, dapibus non sodales quis, volutpat a turpis. Curabitur eget fermentum ante. Donec pulvinar nulla non ante mattis aliquam.Aenean vulputate, ligula sit amet laoreet porttitor, magna justo pellentesque diam, id tempus eros orci ut arcu. Praesent et finibus ipsum. Mauris luctus, metus vel sagittis pharetra, felis odio placerat felis, et ullamcorper neque turpis eget tellus. Maecenas vel imperdiet augue. Morbi imperdiet diam ac enim cursus venenatis. Donec eros turpis, pharetra a aliquet sed, vehicula sed libero. Donec efficitur volutpat ex, in euismod dolor tristique at. Quisque a nisi ultricies libero lacinia fringilla nec vel tortor.Aenean id felis et quam lacinia ornare. Curabitur blandit, arcu eget ultricies pulvinar, neque lectus ultrices mauris, vitae feugiat mauris diam id tellus. Vestibulum finibus cursus dui et feugiat. Sed vitae sagittis lorem. Duis suscipit sollicitudin est tempor efficitur. Morbi eget fringilla massa. Integer ullamcorper, ligula congue consequat sodales, dolor eros pretium augue, in luctus enim massa quis est. Fusce cursus ac ipsum quis aliquet. Curabitur pharetra lectus non suscipit scelerisque. Pellentesque vitae scelerisque tellus. Donec sit amet ligula felis. Donec ac hendrerit magna, sed pharetra diam. Morbi gravida felis finibus sodales suscipit. In hac habitasse platea dictumst.Curabitur purus erat, tincidunt vel tincidunt et, fermentum eget dui. Fusce eu justo vel massa ultrices lacinia sit amet quis augue. Nunc fringilla justo quis felis fringilla, at rutrum justo venenatis. Ut ullamcorper gravida finibus. Donec fermentum varius metus sit amet porttitor. Sed at auctor velit. Quisque et urna metus. Donec ut mi vel turpis dignissim pulvinar. Curabitur massa leo, interdum ac urna id, dictum pellentesque nunc. Ut dolor justo, vehicula quis porta in, laoreet eget augue. this is a test pneumonoultramicroscopicsilicovolcanoconiosis" Dim maxCharacters = 40 Dim result = text.WordWrap(maxCharacters) For Each line In result Display($"Length: {line.Length} - {line}") Next Catch ex As Exception Display(ex.ToString) Finally Console.ReadLine() End Try End Sub Public Sub Display(message As String) Console.WriteLine(message) Debug.Print(message) End Sub End Module ' http://programmingnotes.org/ |
QUICK NOTES:
The highlighted lines are sections of interest to look out for.
The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.
Leave a Reply