Solved

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

Posted on 2009-04-07
9
2,774 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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