• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2784
  • Last Modified:

String functon in vb.net example trim,left,right

Hi,
Can somebody help me in converting the following code to vb.net

Cheers
Public Function CheckNextLine(ByRef Line1 As String, ByRef Line2 As String) As Boolean
        Dim i As Short
        For i = 0 To UBound(List)
            If Left((Line2).ToUpper, Len(List(i))) = List(i) Then
                If Left(UCase(Trim(Line1)), 3) = "IF " OrElse Left(UCase(Trim(Line2)), 1) = "'" Then Exit Function
                CheckNextLine = True
                Exit Function
            End If
        Next
    End Function

Open in new window

0
RIAS
Asked:
RIAS
  • 4
  • 4
2 Solutions
 
CraigLazarCommented:
Hi,
the easiest way to do it is add
Microsoft.VisualBasic. at the front

Microsoft.VisualBasic.Left or
Microsoft.VisualBasic.Right
 
hope this helps
 
0
 
rockiroadsCommented:
your variable List, where is that defined?

you can change List to List.Length, though I think List is a reserved word so use another variable - eg myList

Ubound(list)

same as

myList.length


with this line
If Left((Line2).ToUpper, Len(List(i))) = List(i) Then

you can continue to use Left
eg
            If Left(Line2.ToUpper, myList(i).Length) = myList(i) Then
or you can use substring

if Line2.Substring(1, myList(i).Length) = mylist(i) then

0
 
rockiroadsCommented:
changing ucase(trim(line1) can be done like this

Line1.Trim.ToUpper

0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
RIASAuthor Commented:
Hi,
Cheers for the solution can you suggest on this
 Left(Trim(CurrLine), 2) = "/*"
  Right(Trim(CurrLine), 2) = "*/"  
Trim(Right(CurrLine, Len(CurrLine) - (InStr(CurrLine, "*/") + 1)))
0
 
rockiroadsCommented:
Revisiting this, I think you could use StartsWith

something like this, remember your List is now mylist

    Public Function CheckNextLine(ByRef Line1 As String, ByRef Line2 As String) As Boolean

        Dim i As Integer
        For i = 0 To myList.Length - 1
            If Line2.StartsWith(myList(i)) Then
                If Line1.Trim.ToUpper.StartsWith("IF ") Or _
                   Line2.Trim.StartsWith("'") = True Then
                    CheckNextLine = True
                    Exit Function
                End If
            End If
        Next
    End Function

0
 
rockiroadsCommented:
anywhere you are using left, you can try using StartsWith instead

eg
Left(Trim(CurrLine), 2) = "/*"

could be
CurrLine.Trim.StartsWith("/*")

will return true if it starts with /*, false if not

same principle with Right. Use EndsWith instead

0
 
RIASAuthor Commented:
Cheers mate.You were of great help!!!!!Excellant
0
 
RIASAuthor Commented:
Great Help!!!
0
 
RIASAuthor Commented:
Just a quick question on
Trim(Right(CurrLine, Len(CurrLine) - (InStr(CurrLine, "*/") + 1)))
can't convert it to vb.net
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now