ASP.NET/VB: Trim quotation marks from beginning and end

Using ASP.NET/VB, I would like to trim quotation marks from the beginning and end.

These charactors should be REMOVED if they are the first or last character of the Headline.

"“”
<h2><%#Container.DataItem("Headline")%></h2>

Open in new window

LVL 16
hankknightAsked:
Who is Participating?
 
strickddConnect With a Mentor Commented:
code infront:

 <h2><% FormatTitle(Container.DataItem("Headline"))%></h2>

code behind:

protected function FormatTitle(title As Object) As String
    Dim temp as String
    Dim originalString As String = title.ToString()

    if originalString.StartsWith(""") then
        temp = originalString.SubString(1)
    else
        temp = originalString
    end if

     if temp.EndsWith(""") then
         temp = temp.SubString(0, temp.Length - 1)
    end if

   return temp

end fuction
0
 
disruptCommented:
0
 
hankknightAuthor Commented:
Thanks.  disrupt, this needs to be VB not C#.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
disruptCommented:
"TrimStart and TrimEnd are supposed to take a character array as a parameter. If you type the keyword null instead, it will trim the white space (blank characters)."

you can also just do this:

returnValue.TrimStart( '" ', '“','”' );
returnValue.TrimEnd( '" ', '“','”' );
0
 
disruptCommented:
It will work in vb .net fine just leave out the semicolon at the end :)
0
 
hankknightAuthor Commented:
Thanks, disrupt.   I awarded the points just moments before you made your post.

strickdd, you solution works.
0
All Courses

From novice to tech pro — start learning today.