I want to search a specific part of a string in VB.NET. For example in the string below I want the following part: "Tennis".
Football ... Basketball ... Tennis ... Golf
I'm not sure how I would crop out the other part of the string so that im left with Tennis. Thanks :)
The solution below is my thought... You can use this function in any class you want, you pass it the string you want to check, what we should split on and finally what position do we want to get... I hope you do not mind Linq and lamda expression's...
''' <summary>
''' Return's word at index if it exist.
''' </summary>
''' <param name="Sentence"></param>
''' <param name="SplitString"></param>
''' <param name="Position"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function GetWordAtPosition(ByVal Sentence As String, ByVal SplitString As String, ByVal Position As Integer) As String
Dim ReturnWord As String = String.Empty
Dim ListPossibleWords As New List(Of String)
Try
'First see if we have a string, it's not empty or null, we have something to split on, and the actual word
'at the given position...
If Sentence IsNot Nothing AndAlso Not String.IsNullOrEmpty(Sentence) AndAlso SplitString IsNot Nothing AndAlso Not String.IsNullOrEmpty(SplitString) AndAlso Position > -1 Then
'Trim the string out...
Sentence = Sentence.Trim.Replace(" ", String.Empty)
'Does the string have what we need to split on?
If Sentence.Contains(SplitString) Then
'Split all this into a List(Of String)...
With ListPossibleWords
.AddRange(Strings.Split(Sentence, SplitString.ToCharArray))
.RemoveAll(Function(s As String) As Boolean
Return s.Equals(SplitString)
End Function)
End With
'Do we have a list now?
If ListPossibleWords.Count >= Position Then ReturnWord = ListPossibleWords.Item(Position - 1)
End If
End If
Return ReturnWord
Catch ex As Exception
Return ReturnWord
End Try
End Function
The following might do what you want.
Module VBModule
Sub Main()
Dim sSearchIn As String = "Football ... Basketball ... Tennis ... Golf"
Dim sSearchFor As String = " ... "
Dim lItemPosition As Long = 3
Dim lSkipLen As Long = sSearchFor.Length
Dim lIndex As Long
Dim sTemp as String
Dim i As Long
' Mid is one-based, IndexOf is zero-based
sTemp = sSearchIn
For lIndex = 1 To lItemPosition - 1
sTemp = Mid (sTemp, sTemp.IndexOf(sSearchFor) + 1 + lSkipLen)
Next lIndex
i = sTemp.IndexOf(sSearchFor)
If (i > 0) Then
Console.WriteLine(Left (sTemp, i))
Else
Console.WriteLine(sTemp)
End If
End Sub
End Module
Related
I am able to convert my string to hex value but unable to do the opposite method:
Public Function StringToHex(_str$)
Return BitConverter.ToString(Convert.FromBase64String(_str$))
End Function
Public Function HexToString(_str$)
'could not do this
End Function
Private Sub Button55_Click(sender As Object, e As EventArgs) Handles
Button55.Click
lblStatus.Text = StringToHex("mankat236598")
'result : 99-A9-E4-6A-DD-B7-EB-9F-7C
lblInfo.Text = HexToString( lblStatus.Text)
'i want result : mankat236598
End Sub
As you have a string representation of bytes in a format "00-00-00", you need to convert the "00" etc. to bytes. You can skip the dashes while doing that:
Option Infer On
Option Strict On
Module Module1
Function StringToHex(s As String) As String
Return BitConverter.ToString(Convert.FromBase64String(s))
End Function
''' <summary>
''' Convert hex string to bytes and then Base64 encode those bytes.
''' </summary>
''' <param name="hexString">Hex as a string with dashes between bytes, e.g. A0-10-FF.</param>
''' <returns></returns>
Function HexToString(hexString As String) As String
Dim nBytes = (hexString.Length + 1) \ 3
Dim bb(nBytes - 1) As Byte
For i = 0 To nBytes - 1
Dim b = hexString.Substring(i * 3, 2)
bb(i) = Convert.ToByte(b, 16)
Next
Return Convert.ToBase64String(bb, Base64FormattingOptions.None)
End Function
Sub Main()
Dim testString = "mankat236598"
Dim x = StringToHex(testString)
Console.WriteLine(x)
Dim y = HexToString(x)
' Check if the result is correct:
If y <> testString Then Console.WriteLine("Round-trip failure.")
Console.WriteLine(y)
Console.ReadLine()
End Sub
End Module
I need to split some text, but i'm having trouble with some extra spaces.
The following image shows the usual output text.
I want to add the split values in a checkedlistbox and i have the following code:
Dim SEPARATED = TextBox1.Text.Split(vbCr, vbLf, vbTab, ">") '" "C
CheckedListBox1.Items.Clear()
For Each item In separated
If item <> "" Then CheckedListBox1.Items.Add(item)
Next
CheckedListBox1.Items.Remove("#")
CheckedListBox1.Items.Remove("PI")
Dim MODIFIED As String() = ANSWER.ToString.Split(" ")
buuuuuuut the extra spaces are giving me headaches. I don't know how to split the text in groups of twelve chars ( they're always 12, the spaces complete them) .
In conclusion, using the example, i want to only show "DEFAULT","EX W SPACE","POTATO" and "HELP PLS".
Thank you !
I used the GetOPString() function to return a string with your items in it (DEFAULT","EX W SPACE","POTATO" and "HELP PLS") with a padding of 12 characters. That function you do not need because your source string is already built like that.
I used the following logic
Split source string into lines
If there is a word with no space in front (EXAMPLE), It is some sort of title so I ignore it (you didn't want it in the final result)
Trim word to remove all spaces and starting ">" character if found
See the example below.
You can tweak it according to your need.
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
Dim Rawstring As String = GetOPString("DEFAULT","EX W SPACE","POTATO",">HELP PLS")
Dim SEPARATED As List(Of String) = GetListItems(Rawstring)
For Each Item As String In SEPARATED
CheckedListBox1.Items.Add(Item)
Next
End Sub
''' <summary>
''' Get a list of string by dividing Rawstring into 12 chars sequence.
''' Any space is trimmed and leading > character (if found) is removed.
''' </summary>
''' <param name="RawString"></param>
''' <returns></returns>
Private Function GetListItems(RawString As String) As IEnumerable(Of String)
Dim Output As New List(Of String)
For Each item In RawString.Split(vbCr)
If String.IsNullOrWhiteSpace(item) Then Continue For
Dim AssumeTitle As Boolean = Not String.IsNullOrWhiteSpace(item(0))
If AssumeTitle Then Continue For 'EXAMPLE is the title and we do not want it in the checkbox
item = item.Trim.TrimStart(">"c)
Output.Add(item)
Next
Return Output
End Function
''' <summary>
''' I used this function only to return the string you have in your post,
''' which is, words to be separated in 12 characters sequences.
''' </summary>
''' <returns></returns>
Private Function GetOPString(ByVal ParamArray Words As String()) As String
Dim Output As New Text.StringBuilder
Output.AppendLine("EXAMPLE")
Output.AppendLine()
For Each Item As String In Words
Output.Append(vbTab)
If Not Item.StartsWith(">") Then
Output.Append(" ")
End If
Output.AppendLine(Item.PadRight(12))
Next
Return Output.ToString
End Function
Is there a way to check if a string has all of it's parenthesis closed? So for example it would take as an argument a string like this:
dim ValidOne as string = "This is (good)"
dim ValidOne as string = "This (is (good))"
dim InvalidOne as string = "This is (bad))"
dim InvalidOne as string = "This is (bad"
dim InvalidOne as string = "This is bad)"
And return True or False depending on whether there is a valid number of closed parenthesis.
So it if the string had an open ( and it was not closed, or just a ) that was never opened, it would return false.
I think you can do something like +1 for each open ( and -1 for each ). The rule is that you must end with 0 at the end.
If you want a full versatile and customizable solution then here is my approach:
Output:
Snippet:
''' <summary>
''' Counts the closed and opened pair of chars inside a String.
''' </summary>
''' <param name="PairChars">The pair character.</param>
''' <param name="Input">The string where to count the pair characters.</param>
''' <returns>PairCharacter.</returns>
''' <exception cref="System.Exception">Index of 'PairChar' parameter is out of range.</exception>
Public Function CountPairOfChars(ByVal PairChars As KeyValuePair(Of Char, Char),
ByVal Input As String) As PairOfCharsInfo
If String.IsNullOrEmpty(Input) OrElse String.IsNullOrWhiteSpace(Input) Then
Throw New Exception("'Input' parameter cannot be an empty String.")
End If
Dim CharStack As New Stack(Of Integer)
Dim Result As New PairOfCharsInfo
With Result
.Input = Input
.Characters = New KeyValuePair(Of Char, Char)(PairChars.Key, PairChars.Value)
For i As Integer = 0 To Input.Length - 1
Select Case Input(i)
Case .Characters.Key
CharStack.Push(i)
.OpenedPairsIndex.Add(i)
.CountOpenedPairs += 1
Case .Characters.Value
Select Case CharStack.Count
Case Is = 0
.CountOpenedPairs += 1
.OpenedPairsIndex.Add(i)
Case Else
.CountClosedPairs += 1
.CountOpenedPairs -= 1
.ClosedPairsIndex.Add(Tuple.Create(Of Integer, Integer)(CharStack.Pop, i))
.OpenedPairsIndex.RemoveAt(.OpenedPairsIndex.Count - 1)
End Select '/ CharStack.Count
End Select '/ Input(i)
Next i
.StringHasClosedPairs = .CountClosedPairs <> 0
.StringHasOpenedPairs = .CountOpenedPairs <> 0
End With '/ Result
Return Result
End Function
''' <summary>
''' Stores info about closed and opened pairs of chars in a String.
''' </summary>
Public NotInheritable Class PairOfCharsInfo
''' <summary>
''' Indicates the input string.
''' </summary>
''' <value>The input string.</value>
Public Property Input As String = String.Empty
''' <summary>
''' Indicates the pair of characters.
''' </summary>
''' <value>The pair of characters.</value>
Public Property Characters As KeyValuePair(Of Char, Char) = Nothing
''' <summary>
''' Determines whether the input string contains closed pairs of character.
''' </summary>
''' <value>The closed pairs count.</value>
Public Property StringHasClosedPairs As Boolean = False
''' <summary>
''' Determines whether the input string contains opened pairs of character.
''' </summary>
''' <value>The closed pairs count.</value>
Public Property StringHasOpenedPairs As Boolean = False
''' <summary>
''' Indicates the total amount of closed pairs.
''' </summary>
''' <value>The closed pairs count.</value>
Public Property CountClosedPairs As Integer = 0
''' <summary>
''' Indicates the total amount of opened pairs.
''' </summary>
''' <value>The opened pairs count.</value>
Public Property CountOpenedPairs As Integer = 0
''' <summary>
''' Indicates the closed pairs index position in the string.
''' </summary>
''' <value>The closed pairs positions.</value>
Public Property ClosedPairsIndex As New List(Of Tuple(Of Integer, Integer))
''' <summary>
''' Indicates the opened pairs index position in the string.
''' </summary>
''' <value>The opened pairs positions.</value>
Public Property OpenedPairsIndex As New List(Of Integer)
End Class '/ PairOfCharsInfo
Example Usage:
( The same as I used for the output images above)
Private Sub Test() Handles MyBase.Shown
Dim Inputs As String() =
{
"(This) is (good)",
"This (is (good))",
"This is good",
"This is (bad))",
"This is (bad",
"This is bad)",
"This is bad)("
}
Dim PairChars As New KeyValuePair(Of Char, Char)("(", ")")
For Each s As String In Inputs
Dim Info As PairOfCharsInfo = Me.CountPairOfChars(PairChars, s)
Dim sb As New System.Text.StringBuilder
With sb
.AppendLine(String.Format("Input String: {0}", Info.Input))
.AppendLine(String.Format("Pair of Chars: {0}{1}", Info.Characters.Key, Info.Characters.Value))
.AppendLine()
.AppendLine(String.Format("String has closed pairs?: {0}", Info.StringHasClosedPairs))
.AppendLine(String.Format("String has opened pairs?: {0}", Info.StringHasOpenedPairs))
.AppendLine()
.AppendLine(String.Format("Closed Pairs Count: {0}", Info.CountClosedPairs))
.AppendLine(String.Format("Opened Pairs Count: {0}", Info.CountOpenedPairs))
.AppendLine()
.AppendLine("Closed Pairs Indexes:")
For Each Item As Tuple(Of Integer, Integer) In Info.ClosedPairsIndex
.AppendLine(String.Format("Start Index: {0}, End Index: {1}",
CStr(Item.Item1), CStr(Item.Item2)))
Next Item
.AppendLine()
.AppendLine(String.Format("Opened Pairs Indexes: {0}",
String.Join(", ", Info.OpenedPairsIndex)))
End With '/ sb
MessageBox.Show(sb.ToString, "Count Pair Characters Information",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Next s
End Sub
Something like this should do it:
Public Shared Function TestStringParens(s As String) As Boolean
Dim Ret = 0
For Each C In s
If C = ")"c Then Ret -= 1
If C = "("c Then Ret += 1
'Bail earlier for a closed paren without a matching open
If Ret < 0 Then Return False
Next
Return Ret = 0
End Function
As your post and some other people have said just keep a counter around and walk the string. As #Drico said, any time a negative counter exists then we have a closed parentheses without a corresponding open.
You can test this with:
Dim Tests As New Dictionary(Of String, Boolean)
Tests.Add("This is (good)", True)
Tests.Add("This (is (good))", True)
Tests.Add("This is good", True)
Tests.Add("This is (bad))", False)
Tests.Add("This is (bad", False)
Tests.Add("This is bad)", False)
Tests.Add("This is bad)(", False)
For Each T In Tests
Console.WriteLine(TestStringParens(T.Key) = T.Value)
Next
Here is an example of how you use the mid function to loop through a string
Function checkPar(s As String) As Boolean
Dim i As Integer
Dim parCounter As Integer
parCounter = 0
For i = 1 To Len(s)
If Mid(s, i, 1) = "(" Then
parCounter = parCounter + 1
ElseIf Mid(s, i, 1) = ")" Then
parCounter = parCounter - 1
End If
If parCounter < 0 Then Exit For
Next
If parCounter <> 0 Then
checkPar = False
Else
checkPar = True
End If
End Function
I am using VB.net VS2012 and am having trouble with getting a list of files with a filter.
Here is my code:
Public Function SearchAndAddToListWithFilter(ByVal path As String, ByVal Recursive As Boolean, arrayListOfFilters As ArrayList, ByRef listOfFiles As List(Of FileInfo))
If Not Directory.Exists(path) Then Exit Function
Dim initDirInfo As New DirectoryInfo(path)
For Each oFileInfo In initDirInfo.GetFiles
Application.DoEvents()
For x = 0 To arrayListOfFilters.Count - 1
If (oFileInfo.Name Like arrayListOfFilters(x)) Then
listOfFiles.Add(oFileInfo)
End If
Next
Next
If Recursive Then
For Each oDirInfo In initDirInfo.GetDirectories
SearchAndAddToListWithFilter(oDirInfo.FullName, True, arrayListOfFilters, listOfFiles)
Next
End If
End Function
And here is an example of how to use it:
Dim stringFilterList As String = "*.mp3, *.docx, *.mp3, *.txt"
Dim arrayListOfFilenameFilters As New ArrayList(stringFilterList.Split(","))
Dim stringFolderPath As String = "C:\temp\folder\"
Dim booleanSearchSubFolders As Boolean = True
Dim listOfFilesFoundViaSearch As New List(Of FileInfo)
SearchAndAddToListWithFilter(stringFolderPath, booleanSearchSubFolders, arrayListOfFilenameFilters, listOfFilesFoundViaSearch)
For x = 0 To listOfFilesFoundViaSearch.Count - 1
MsgBox(listOfFilesFoundViaSearch(x).FullName)
Next
For some reason, the code only adds the files to the list that satisy the first condition in the list of filters.
Can I please have some help to get this code working?
Thank you.
Functions return values, and passing a value ByRef is NOT the way to do it.
The following function will work:
Private Function SearchAndAddToListWithFilter(ByVal path As String, ByVal filters As String(), ByVal searchSubFolders As Boolean) As List(Of IO.FileInfo)
If Not IO.Directory.Exists(path) Then
Throw New Exception("Path not found")
End If
Dim searchOptions As IO.SearchOption
If searchSubFolders Then
searchOptions = IO.SearchOption.AllDirectories
Else
searchOptions = IO.SearchOption.TopDirectoryOnly
End If
Return filters.SelectMany(Function(filter) New IO.DirectoryInfo(path).GetFiles(filter, searchOptions)).ToList
End Function
and to use this function:
Dim filters As String() = {"*.mp3", "*.docx", "*.bmp", "*.txt"}
Dim path As String = "C:\temp\folder\"
Dim foundFiles As List(Of IO.FileInfo) = SearchAndAddToListWithFilter(path, filters, True)
The solution provided by #Steve really shows the .NET way of doing the task.
However I used a recursive solution with possible definitions of maximum depth and/or duration. For completeness of this topic, I want to post the code:
''' <summary>
''' Search files in directory and subdirectories
''' </summary>
''' <param name="searchDir">Start Directory</param>
''' <param name="searchPattern">Search Pattern</param>
''' <param name="maxDepth">maximum depth; 0 for unlimited depth</param>
''' <param name="maxDurationMS">maximum duration; 0 for unlimited duration</param>
''' <returns>a list of filenames including the path</returns>
''' <remarks>
''' recursive use of Sub dirS
'''
''' wallner-novak#bemessung.at
''' </remarks>
Public Shared Function dirRecursively(searchDir As String, searchPattern As String, _
Optional maxDepth As Integer = 0, _
Optional maxDurationMS As Long = 0) As List(Of String)
Dim fileList As New List(Of String)
Dim depth As Integer = 0
Dim sw As New Stopwatch
dirS(searchDir, searchPattern, maxDepth, maxDurationMS, fileList, depth, sw)
Return fileList
End Function
''' <summary>
''' Recursive file search
''' </summary>
''' <param name="searchDir">Start Directory</param>
''' <param name="searchPattern">Search Pattern</param>
''' <param name="maxDepth">maximum depth; 0 for unlimited depth</param>
''' <param name="maxDurationMS">maximum duration; 0 for unlimited duration</param>
''' <param name="fileList">Filelist to append to</param>
''' <param name="depth">current depth</param>
''' <param name="sw">stopwatch</param>
''' <param name="quit">boolean value to quit early (at given depth or duration)</param>
''' <remarks>
''' wallner-novak#bemessung.at
''' </remarks>
Private Shared Sub dirS(searchDir As String, searchPattern As String, _
Optional maxDepth As Integer = 0, _
Optional maxDurationMS As Long = 0, _
Optional ByRef fileList As List(Of String) = Nothing, _
Optional ByRef depth As Integer = 0, _
Optional ByRef sw As Stopwatch = Nothing, _
Optional ByRef quit As Boolean = False)
If maxDurationMS > 0 Then
If depth = 0 Then
sw = New Stopwatch
sw.Start()
Else
If sw.ElapsedMilliseconds > maxDurationMS Then
quit = True
Exit Sub
End If
End If
End If
If maxDepth > 0 Then
If depth > maxDepth Then
quit = True
Exit Sub
End If
End If
' check if directory exists
If Not Directory.Exists(searchDir) Then
Exit Sub
End If
' find files
For Each myFile As String In Directory.GetFiles(searchDir, searchPattern)
fileList.Add(myFile)
Next
' recursively scan subdirectories
For Each myDir In Directory.GetDirectories(searchDir)
depth += 1
dirS(myDir, searchPattern, maxDepth, maxDurationMS, fileList, depth, sw, quit)
If quit Then Exit For
depth -= 1
Next
End Sub
ListView1.Items.Clear()
For Each files As String In System.IO.Directory.GetFiles(cmb_Drives.SelectedItem.ToString, txtSearch.Text)
Dim ico As Icon = System.Drawing.Icon.ExtractAssociatedIcon(files)
ImageList1.Images.Add(ico)
Dim list As ListViewItem = New ListViewItem(My.Computer.FileSystem.GetFileInfo(files).FullName, ImageList1.Images.Count - 1)
ListView1.Items.Add(list)
Next
How do i Declare a string like this:
Dim strBuff As String * 256
in VB.NET?
Use the VBFixedString attribute. See the MSDN info here
<VBFixedString(256)>Dim strBuff As String
It depends on what you intend to use the string for. If you are using it for file input and output, you might want to use a byte array to avoid encoding problems. In vb.net, A 256-character string may be more than 256 bytes.
Dim strBuff(256) as byte
You can use encoding to transfer from bytes to a string
Dim s As String
Dim b(256) As Byte
Dim enc As New System.Text.UTF8Encoding
...
s = enc.GetString(b)
You can assign 256 single-byte characters to a string if you need to use it to receive data, but the parameter passing may be different in vb.net than vb6.
s = New String(" ", 256)
Also, you can use vbFixedString. I'm not sure exactly what this does, however, because when you assign a string of different length to a variable declared this way, it becomes the new length.
<VBFixedString(6)> Public s As String
s = "1234567890" ' len(s) is now 10
To write this VB 6 code:
Dim strBuff As String * 256
In VB.Net you can use something like:
Dim strBuff(256) As Char
Use stringbuilder
'Declaration
Dim S As New System.Text.StringBuilder(256, 256)
'Adding text
S.append("abc")
'Reading text
S.tostring
Try this:
Dim strbuf As New String("A", 80)
Creates a 80 character string filled with "AAA...."'s
Here I read a 80 character string from a binary file:
FileGet(1,strbuf)
reads 80 characters into strbuf...
You can use Microsoft.VisualBasic.Compatibility:
Imports Microsoft.VisualBasic.Compatibility
Dim strBuff As New VB6.FixedLengthString(256)
But it's marked as obsolete and specifically not supported for 64-bit processes, so write your own that replicates the functionality, which is to truncate on setting long values and padding right with spaces for short values. It also sets an "uninitialised" value, like above, to nulls.
Sample code from LinqPad (which I can't get to allow Imports Microsoft.VisualBasic.Compatibility I think because it is marked obsolete, but I have no proof of that):
Imports Microsoft.VisualBasic.Compatibility
Dim U As New VB6.FixedLengthString(5)
Dim S As New VB6.FixedLengthString(5, "Test")
Dim L As New VB6.FixedLengthString(5, "Testing")
Dim p0 As Func(Of String, String) = Function(st) """" & st.Replace(ChrW(0), "\0") & """"
p0(U.Value).Dump()
p0(S.Value).Dump()
p0(L.Value).Dump()
U.Value = "Test"
p0(U.Value).Dump()
U.Value = "Testing"
p0(U.Value).Dump()
which has this output:
"\0\0\0\0\0"
"Test "
"Testi"
"Test "
"Testi"
This object can be defined as a structure with one constructor and two properties.
Public Structure FixedLengthString
Dim mValue As String
Dim mSize As Short
Public Sub New(Size As Integer)
mSize = Size
mValue = New String(" ", mSize)
End Sub
Public Property Value As String
Get
Value = mValue
End Get
Set(value As String)
If value.Length < mSize Then
mValue = value & New String(" ", mSize - value.Length)
Else
mValue = value.Substring(0, mSize)
End If
End Set
End Property
End Structure
https://jdiazo.wordpress.com/2012/01/12/getting-rid-of-vb6-compatibility-references/
Have you tried
Dim strBuff as String
Also see Working with Strings in .NET using VB.NET
This tutorial explains how to
represent strings in .NET using VB.NET
and how to work with them with the
help of .NET class library classes.
Dim a as string
a = ...
If a.length > theLength then
a = Mid(a, 1, theLength)
End If
This hasn't been fully tested, but here's a class to solve this problem:
''' <summary>
''' Represents a <see cref="String" /> with a minimum
''' and maximum length.
''' </summary>
Public Class BoundedString
Private mstrValue As String
''' <summary>
''' The contents of this <see cref="BoundedString" />
''' </summary>
Public Property Value() As String
Get
Return mstrValue
End Get
Set(value As String)
If value.Length < MinLength Then
Throw New ArgumentException(String.Format("Provided string {0} of length {1} contains less " &
"characters than the minimum allowed length {2}.",
value, value.Length, MinLength))
End If
If value.Length > MaxLength Then
Throw New ArgumentException(String.Format("Provided string {0} of length {1} contains more " &
"characters than the maximum allowed length {2}.",
value, value.Length, MaxLength))
End If
If Not AllowNull AndAlso value Is Nothing Then
Throw New ArgumentNullException(String.Format("Provided string {0} is null, and null values " &
"are not allowed.", value))
End If
mstrValue = value
End Set
End Property
Private mintMinLength As Integer
''' <summary>
''' The minimum number of characters in this <see cref="BoundedString" />.
''' </summary>
Public Property MinLength() As Integer
Get
Return mintMinLength
End Get
Private Set(value As Integer)
mintMinLength = value
End Set
End Property
Private mintMaxLength As Integer
''' <summary>
''' The maximum number of characters in this <see cref="BoundedString" />.
''' </summary>
Public Property MaxLength As Integer
Get
Return mintMaxLength
End Get
Private Set(value As Integer)
mintMaxLength = value
End Set
End Property
Private mblnAllowNull As Boolean
''' <summary>
''' Whether or not this <see cref="BoundedString" /> can represent a null value.
''' </summary>
Public Property AllowNull As Boolean
Get
Return mblnAllowNull
End Get
Private Set(value As Boolean)
mblnAllowNull = value
End Set
End Property
Public Sub New(ByVal strValue As String,
ByVal intMaxLength As Integer)
MinLength = 0
MaxLength = intMaxLength
AllowNull = False
Value = strValue
End Sub
Public Sub New(ByVal strValue As String,
ByVal intMinLength As Integer,
ByVal intMaxLength As Integer)
MinLength = intMinLength
MaxLength = intMaxLength
AllowNull = False
Value = strValue
End Sub
Public Sub New(ByVal strValue As String,
ByVal intMinLength As Integer,
ByVal intMaxLength As Integer,
ByVal blnAllowNull As Boolean)
MinLength = intMinLength
MaxLength = intMaxLength
AllowNull = blnAllowNull
Value = strValue
End Sub
End Class