Solved

remove leading string

Posted on 2010-08-12
9
218 Views
Last Modified: 2012-05-10
How can I remove  " or " from this string? I want to remove the leading  "or"
string " or id='1' or id=' 2' or etc
I want "id='1' or id='2'
0
Comment
Question by:VBdotnet2005
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33422387
Dim s As String = "or id =1"
        Dim newS As String = Trim(Replace(s, "or ", ""))
0
 
LVL 4

Expert Comment

by:stevepicks
ID: 33422411
<?
$text= " or id='1' or id='2' or";
$trimmed = trim($text);
$trimmed = trim($trimmed, "or");
echo $trimmed;

?>
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33422431
even this gives you what you want
Dim s As String = " or id='1' or id=' 2'"
        Dim newS As String = Trim(Replace(s, "or ", ""))
0
Industry Leaders: 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:VBdotnet2005
ID: 33422715
I want to remove only leading "or"
or id='1' or id=' 2'
to  id='1' or id=' 2'  etc
0
 
LVL 4

Accepted Solution

by:
stevepicks earned 32 total points
ID: 33422731
Sorry
here is the vb.net version of my initial code (which was php)

Dim text1 As String = " or id='1' or id='2'"
        Dim charsToTrim As Char() = "or"
        Dim stripped As String = Trim(text1)
        stripped = stripped.Trim(charsToTrim)

hope it helps
Cheers
0
 
LVL 17

Assisted Solution

by:Zhaolai
Zhaolai earned 62 total points
ID: 33422750
       Dim strTemp As String = " or id='1' or id=' 2'"
        strTemp = strTemp.Trim.TrimStart(New Char() {"o", "r"}).Trim


0
 
LVL 17

Assisted Solution

by:Zhaolai
Zhaolai earned 62 total points
ID: 33422845
Even simpler:

        Dim strTemp As String = " or id='1' or id=' 2'"
        strTemp = strTemp.TrimStart(New Char() {" ", "o", "r"})


0
 
LVL 18

Assisted Solution

by:John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou earned 31 total points
ID: 33423296
Or Very simple
Dim s As String
        s = "or id='1' or id=' 2'"
        Dim s1 As String = s.Remove(0, 3)
        Dim s2 As String = Trim(s1)
        Me.Label1.Text = s2

Open in new window

0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33435167
Interesting...
I just tested the accepted solution. It leaves a leading space in the resulting string.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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 …
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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