logo  VB.Net - String Processing
This Chapter
Number Text
String Functions
Chapters
Home Page
Colours, RGB
Computer Specifications
Dates&Times
Disk Drives
Files
Folders
GPS and OS Ref
VB.Net Forms
Image Files
If & Select
List/Array
Mathematics
NuGet
Sound
String Functions
Sun and Moon
User Controls
Validation
DigitalDan Sites
My Other Sites
Contact Site

Note
Some pages
may contain
inaccuracies
Hits=5
Left and Right Characters

Private Function Left(s As String, n As Integer) As String
 Return Microsoft.VisualBasic.Left(s, n)
End Function
'
Private Function Right(s As String, n As Integer) As String
 Return Microsoft.VisualBasic.Right(s, n)
End Function
  
Remove all Accents
Removing accents can cause unexpected problems, e.g. removal of an accent could change the pronuncuation and meaning of a word! It should be avoided but you encounter situations where there is no alternative (e.g. preparing text for a segmented LED text display.

Public Function RemoveAccents(value As String) As String
 Dim normalizedString As String = value.Normalize(System.Text.NormalizationForm.FormD)
 Dim stringBuilder As New System.Text.StringBuilder()
 For Each c As System.Text.Rune In normalizedString.EnumerateRunes()
  Dim unicodeCategory1 = System.Text.Rune.GetUnicodeCategory(c)
  If (unicodeCategory1 <> System.Globalization.UnicodeCategory.NonSpacingMark) Then stringBuilder.Append(c)
 Next
 Return stringBuilder.ToString().Normalize(System.Text.NormalizationForm.FormC)
End Function
  
Test For Special Characters
Two-Byte and non-printing characters can cause problems in some circumstances. E.g.

Public Function ContainsSpecialCharacters(s As String) As Boolean
 Dim r As New System.Text.RegularExpressions.Regex("[^\x20-\x7e]")
 Return r.IsMatch(s)
End Function
  

DigitalDan.co.uk