Solved

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

Posted on 2009-04-07
9
2,779 Views
Last Modified: 2013-11-07
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
Comment
Question by:RIAS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 4

Expert Comment

by:CraigLazar
ID: 24085744
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
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 24085748
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 24085753
changing ucase(trim(line1) can be done like this

Line1.Trim.ToUpper

0
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 

Author Comment

by:RIAS
ID: 24085781
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
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 500 total points
ID: 24085817
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 24085830
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
 

Author Comment

by:RIAS
ID: 24085894
Cheers mate.You were of great help!!!!!Excellant
0
 

Author Closing Comment

by:RIAS
ID: 31567424
Great Help!!!
0
 

Author Comment

by:RIAS
ID: 24087648
Just a quick question on
Trim(Right(CurrLine, Len(CurrLine) - (InStr(CurrLine, "*/") + 1)))
can't convert it to vb.net
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question