String To Hex and Hex to String - vb.net

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

Related

VB.NET Search string

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

Check if a string has all of it's parenthesis closed

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

How to find a numeric value in a string

I am attempting to create a method which analyzes a string of text to see if it contains a numeric value. For instance, given the following string:
What is 2 * 2?
I need to determine the following information:
The string contains a numeric value: True
What is the numeric value that it contains: 2 (anyone of them should make the function return true and I should put the position of each of the 2's in the string in a variable such as position 0 for the first 2)
Here is the code I have so far:
Public Function InQuestion(question As String) As Boolean
' Possible substring operations using the position of the number in the string?
End Function
Here's an example console application:
Module Module1
Sub Main()
Dim results As List(Of NumericValue) = GetNumericValues("What is 2 * 2?")
For Each i As NumericValue In results
Console.WriteLine("{0}: {1}", i.Position, i.Value)
Next
Console.ReadKey()
End Sub
Public Class NumericValue
Public Sub New(value As Decimal, position As Integer)
Me.Value = value
Me.Position = position
End Sub
Public Property Value As Decimal
Public Property Position As Integer
End Class
Public Function GetNumericValues(data As String) As List(Of NumericValue)
Dim values As New List(Of NumericValue)()
Dim wordDelimiters() As Char = New Char() {" "c, "*"c, "?"c}
Dim position As Integer = 0
For Each word As String In data.Split(wordDelimiters, StringSplitOptions.None)
Dim value As Decimal
If Decimal.TryParse(word, value) Then
values.Add(New NumericValue(value, position))
End If
position += word.Length + 1
Next
Return values
End Function
End Module
As you can see, it passes the string `"What is 2 * 2?" and it outputs the positions and values of each numeric value:
8: 2
12: 2

How to correctly read a random access file in VB.NET

I am attempting to read a random access file, but I am getting the following error on the first file Error 5 (unable to read beyond end of the stream). I am not sure what I am doing wrong here, how might I fix this issue?
Structure StdSections
'UPGRADE_WARNING: Fixed-length string size must fit in the buffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="3C1E4426-0B80-443E-B943-0627CD55D48B"'
<VBFixedString(15), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=15)> Public A() As Char 'BEAM --- complete beam designation 15
'UPGRADE_WARNING: Fixed-length string size must fit in the buffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="3C1E4426-0B80-443E-B943-0627CD55D48B"'
<VBFixedString(2), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=2)> Public B() As Char 'DSG --- shape ie "W" or "C" 2
Dim C As Single 'DN --- nominal depth of section 4
Dim d As Single 'WGT --- weight 4
.
.
.
End structure
''Note 'File1'is the existing RAF and holds complete path!
Dim i,ffr,fLength,lastmembNo as integer
sectionFound = False
Dim std As new StdSections
fLength = Len(std)
If fLength = 0 Then fLength = 168 ' 177
ffr = FreeFile()
FileOpen(ffr, File1, OpenMode.Random, OpenAccess.Read, OpenShare.LockRead, fLength)
lastmembNo = CInt(LOF(ffr)) \ fLength
For i = 1 To lastmembNo
FileGet(ffr, std, i)
>>Error 5 (unable to read beyond end of the stream) <<<
If Trim(memberID) = Trim(std.A) Then
sectionFound = True
end if
next i
Wow Freefile! That's a blast from the past!
I haven't really used the old OpenFile etc. file access methods in VB.NET, so I'm just speculating, but in .NET many of the variable types got changed in size. e.g. an Integer is now 32-bits (4 bytes), I think a Boolean is different, though a Single is still 4 bytes.
Also, strings in .NET are by default in Unicode, not ASCII, so you cannot rely on 1 character=1 byte in a .NET String variable. In fact, .NET actualy "JIT compiles" programs on the PC before running, so you can't really lay out structures in memory easily like the old days.
If you want to switch to the new "Stream" based objects, here's some code to get you started:
Dim strFilename As String = "C:\Junk\Junk.txt"
Dim strTest As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Call My.Computer.FileSystem.WriteAllText(strFilename, strTest, False)
Dim byt(2) As Byte
Using fs As New FileStream(strFilename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)
fs.Seek(16, SeekOrigin.Begin)
fs.Read(byt, 0, 3)
Dim s As String = Chr(byt(0)) & Chr(byt(1)) & Chr(byt(2))
MsgBox(s)
fs.Seek(5, SeekOrigin.Begin)
fs.Write(byt, 0, 3)
End Using
Dim strModded As String = My.Computer.FileSystem.ReadAllText(strFilename)
MsgBox(strModded)
I wouldn't blame you for keeping the old method though: with the new method, you'll need to define a class, and then have a custom routine to convert from Byte() to the properties of the class. More work than simply loading bytes from the file into memory.
OK, I think you should switch to the ".NET way", as follows:
Imports System.IO
Imports System.Xml
Public Class Form1
Public Const gintRecLen_CONST As Integer = 177
Class StdSections2
Private mstrA As String
Public Property A() As String
Get
Return mstrA
End Get
Set(ByVal value As String)
If value.Length <> 15 Then
Throw New Exception("Wrong size")
End If
mstrA = value
End Set
End Property
Private mstrB As String
Public Property B() As String
Get
Return mstrB
End Get
Set(ByVal value As String)
If value.Length <> 2 Then
Throw New Exception("Wrong size")
End If
mstrB = value
End Set
End Property
Public C(39) As Single
Public Shared Function FromBytes(byt() As Byte) As StdSections2
Dim output As New StdSections2
If byt.Length <> gintRecLen_CONST Then
Throw New Exception("Wrong size")
End If
For i As Integer = 0 To 14
output.mstrA &= Chr(byt(i))
Next i
For i As Integer = 15 To 16
output.mstrB &= Chr(byt(i))
Next i
For i As Integer = 0 To 39
Dim bytTemp(3) As Byte
output.C(i) = BitConverter.ToSingle(byt, 17 + 4 * i)
Next i
Return output
End Function
End Class
Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim strFilename As String = "C:\Junk\Junk.txt"
Dim strMemberID As String = "foo"
Dim intRecCount As Integer = CInt(My.Computer.FileSystem.GetFileInfo(strFilename).Length) \ gintRecLen_CONST
Dim blnSectionFound As Boolean = False
Using fs As New FileStream(strFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
For intRec As Integer = 0 To intRecCount - 1
Dim intRecPos As Integer = gintRecLen_CONST * intRec
fs.Seek(intRecPos, SeekOrigin.Begin)
Dim byt(gintRecLen_CONST - 1) As Byte
fs.Read(byt, 0, gintRecLen_CONST)
Dim ss2 As StdSections2 = StdSections2.FromBytes(byt)
'MsgBox(ss2.A & ":" & ss2.C(3)) 'debugging
If strMemberID.Trim = ss2.A.Trim Then
blnSectionFound = True
Exit For
End If
Next intRec
End Using
MsgBox(blnSectionFound.ToString)
End Sub
End Class
We define a class called StdSections2 which uses .NET strings and an array of Singles. We use 0-based arrays everywhere. We load the file using the new FileStream object, and use the Seek() command to find the position we want. We then load raw bytes out of the file, and use Chr() and BitConverter.ToSingle() to convert the raw bytes into strings and singles.
I'm not sure about your example but this one however, works:
Public Class Form1
Const maxLenName = 30
Structure person
<VBFixedString(maxLenName)> Dim name As String
Dim age As Byte
End Structure
Private Sub Form1_Load(sender As [Object], e As EventArgs) Handles MyBase.Load
Dim entryIn As New person
Dim recordLen As Integer = Len(entryIn)
Dim entry As person
If FileIO.FileSystem.FileExists("test.raf") Then Kill("test.raf")
FileOpen(1, "test.raf", OpenMode.Random,,, recordLen)
'write
entry.name = LSet("Bill", maxLenName)
entry.age = 25
FilePut(1, entry, 6) 'write to 6th record
'read
Dim nRecords As Integer = LOF(1) \ recordLen
FileGet(1, entryIn, nRecords)
FileClose(1)
Dim personName As String = RTrim(entryIn.name)
Dim personAge As Byte = entryIn.age
MsgBox(personName & "'s age is " & personAge)
End Sub
End Class

How to declare a fixed-length string in VB.NET?

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