String Manipulation - Getting certain data from a string

 Hello all,

 Using VB I'm trying to have a multiline textbox that a user will put in a quantity and a name as follows:

3xApple
2xPear
4xOrange

And when they click a button I want each part of this as a separate value, so far I have the following:

 

Function GetSingleCards(ByVal AllFruits As String) As String
        
  Dim OurFruits As String() = Nothing
  Dim SingleFruit As String
  Dim ReturnThis As String
    
  OurFruit = AllFruits.Split(vbCrLf)
    
  For Each SingleFruit In OurFruits
         
    ReturnThis &= SingleFruit & ", "
   
    'Later on we will use this section to insert each fruit in a database
   
  Next SingleFruit
       
  Return ReturnThis
       
End Function

  

Now, the question is how would I then get the quantity and the fruit name seperated ready so I can then insert them into my database in seperate fields?

 Thanks in advance! :)

0
Seraphi
2/12/2009 12:28:28 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

4 Replies
826 Views

Similar Articles

[PageSpeed] 34

 Hello!!

i am giving a link where you can find how to manipute string

http://codeasp.net/blogs/vinay_jss/microsoft.net/110/how-to-manipulate-the-string-in-c

http://msdn.microsoft.com/en-us/library/aa260972(VS.60).aspx

 

Hope this will help...


Sincerely,
Vinay Kumar Gupta

Code Review Service || Join now: CodeASP.NET Community || Recent Blogs postings || new forum

Please mark the most helpful reply/replies as "Answer".
0
vinay_jss
2/12/2009 12:43:50 PM

Simple answer:

SingleFruit.Split("x")(0) // is the Quantity

SingleFruit.Split("x")(1) // is the fruit.

But that won't work for fruits with an "x" in them...not that I can think of any...but there might be!

0
Mr
2/12/2009 1:18:43 PM
    Function GetSingleCards(ByVal AllFruits As String) As String

        Dim OurFruits As String() = Nothing
        Dim SingleFruit As String
        Dim ReturnThis As String

        OurFruits = AllFruits.Split(vbCrLf)

        For Each SingleFruit In OurFruits

            ReturnThis &= SingleFruit & ", "

            'Later on we will use this section to insert each fruit in a database
            Dim Quantity As String = SingleFruit.Substring(0, SingleFruit.IndexOf("x"))
            Dim Fruit As String = SingleFruit.Substring(SingleFruit.IndexOf("x") + 1)

        Next SingleFruit

        Return ReturnThis

    End Function
 
0
AustinLei
2/12/2009 2:04:22 PM

 Thanks all!

 Austin's solution works perfectly! :)

0
Seraphi
2/12/2009 4:45:14 PM
Reply:

Web resources about - String Manipulation - Getting certain data from a string - asp.net.getting-started

Photo manipulation - Wikipedia, the free encyclopedia
In digital editing, photographs are usually taken with a digital camera and input directly into a computer. Transparencies , negatives or printed ...

Facebook uses random sampling to determine app ratings and avoid manipulation
... users are randomly prompted to provide star ratings through modules around the site. This unique approach discourages user or developer manipulation. ...

App Store - Psychological manipulation technique [Jane traditional]
Get Psychological manipulation technique [Jane traditional] on the App Store. See screenshots and ratings, and read customer reviews.

Amputation et Manipulation - Flickr - Photo Sharing!
Explore mediafury's photos on Flickr. mediafury has uploaded 4076 photos to Flickr.

Part 1- JP Morgan Silver Manipulation Explained - YouTube
Too big too fail banks like JPM and HSBC have been artificially manipulating the price of silver and gold, scamming the tax payer, and ultimately ...

Barnaby Joyce polishes his rough edges but metaphoric manipulations persist
This popular Nationals MP has repeatedly produced metaphoric manipulations which have left audiences dazzled and dazed.

Was The Voice a simple case of emotional manipulation?
Was The Voice a simple case of emotional manipulation?

Day trader Nigel Heath jailed for market manipulation
A day trader has been sentenced to two years and three months in prison for manipulating the share price of four speculative mining stocks.

ABC in a bind: Tony Abbott's Q&A boycott a masterstroke of media manipulation
At first glance, it seems our prime minister has had an ill-tempered outburst. Look closer and you'll see he's coolly punishing a program he ...

Healthzone directors charged with market manipulation
Three former directors of failed health-food chain Healthzone have been charged with conspiring to manipulate the company's share price in the ...

Resources last updated: 12/2/2015 6:23:50 AM