Solved

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

Posted on 2009-04-07
9
2,769 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
  • 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
 

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now