Phill,[color=blue]
> Are you sure the substring contains /exactly/ 10 /spaces/?
> Could any of them be Null or other whitespace characters?
> Trim() will only remove spaces.[/color]
Interesting, according to MSDN String.Trim() will remove whitespace
characters, it suggests it is using Char.IsWhiteSpace to determine what is a
whitespace character!
http://msdn.microsoft.com/library/de...trimtopic1.asp
Testing shows (see below) that String.Trim() works with: ChrW(9), ChrW(10),
ChrW(11), ChrW(12), ChrW(13), ChrW(32), ChrW(12288)
However try any of the following and it fails:
ChrW(133), ChrW(160), ChrW(5760), ChrW(8192), ChrW(8193)
ChrW(8194), ChrW(8195), ChrW(8196), ChrW(8197), ChrW(8198)
ChrW(8199), ChrW(8200), ChrW(8201), ChrW(8202), ChrW(8203)
ChrW(8232), ChrW(8233), ChrW(8239)
According to Char.IsWhiteSpace all of the above are whitespace characters!
ChrW(133) is the "NEL" or Next Line control char. ChrW(160) is a non
breaking space
http://www.unicode.org/charts/PDF/U0080.pdf
CharW(5760) is the Ogham space mark.
http://www.unicode.org/charts/PDF/U1680.pdf
CharW(8192) to ChrW(8239) are various width spaces:
http://www.unicode.org/charts/PDF/U2000.pdf
Sample code I used to test with:
Const format As String = "ChrW({0})"
Dim sb As New StringBuilder
For charCode As Integer = AscW(Char.MinValue) To AscW(Char.MaxValue)
Dim ch As Char = ChrW(charCode)
If Char.IsWhiteSpace(ch) Then
sb.Append(ch)
Debug.WriteLine(String.Format(format, charCode),
"IsWhiteSpace")
End If
Next
Dim str As String = sb.ToString().Trim()
Debug.WriteLine(str, "str")
Debug.WriteLine(str.Length, "str.length")
Debug.WriteLine(Nothing)
For Each ch As Char In str
Dim charCode As Integer = AscW(ch)
Debug.WriteLine(String.Format(format, charCode), "not trimmed")
Next
If you really needed them trimmed a workaround would be to use
String.Trim(Char())
Static whitespace() As Char = {ChrW(&H9), ChrW(&HA), ChrW(&HB), _
ChrW(&HC), ChrW(&HD), ChrW(&H20), ChrW(&H85), ChrW(&HA0), _
ChrW(&H1680), ChrW(&H2000), ChrW(&H2001), ChrW(&H2002), _
ChrW(&H2003), ChrW(&H2004), ChrW(&H2005), ChrW(&H2006), _
ChrW(&H2007), ChrW(&H2008), ChrW(&H2009), ChrW(&H200A), _
ChrW(&H200B), ChrW(&H2028), ChrW(&H2029), ChrW(&H202F), _
ChrW(&H3000)}
Dim str As String = sb.ToString().Trim(whitespace)
Hope this helps
Jay
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:cvht31$l1p$1@yarrow.open.ac.uk...[color=blue]
> "Darren Anderson" <DarrenAnderson@discussions.microsoft.com> wrote in
> message news:963E2040-E02A-4880-BC3B-8395BB25E2A4@microsoft.com...[color=green]
>> I have a function that I've tried using in an if then statement and
>> I've found that no matter how much reworking I do with the code,
>> the expected result is incorrect.
>>
>> If Not (strIn.Substring(410, 10).Trim = "") Then[/color]
>
> Are you sure the substring contains /exactly/ 10 /spaces/?
> Could any of them be Null or other whitespace characters?
> Trim() will only remove spaces.
>
> Is strIn /at least/ 419 characters long? VB will get upset if you
> try to slice out a substring that's doesn't fit within the source string,
> as in
>
> "abc".SubString( 2, 2 ) ' fails
>
> You're /not/ using "On Error Resume Next", /are/ you?
>
> HTH,
> Phill W.
>
>[/color]