?
Solved

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

Posted on 2009-04-07
9
Medium Priority
?
2,780 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 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

762 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