Solved

put " ' " in front of each number Asp.net (vb)

Posted on 2006-11-16
4
243 Views
Last Modified: 2010-04-16
I have a string

string = 0000000,1111111,2222222,3333333

I want to put " ' " in front of each number so the string should look like

string = '0000000','1111111','2222222','3333333'


each number in the string is 7 digits long.

How do i do this.

Thanks
0
Comment
Question by:pratikshahse
  • 2
4 Comments
 
LVL 35

Expert Comment

by:Raynard7
ID: 17962517
stringName = "'" & stringName.Replace(",", "'.'") & "'"
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17962519
sorry typeo

stringName = "'" & stringName.Replace(",", "','") & "'"

so if you replace the comma with a ',' it will do everything except for the start and finish - so you can then put in a single inverted comma
0
 
LVL 8

Expert Comment

by:deadite
ID: 17963745
Here is a script that is one better.... It'll add the ' at the beginning and end of the string, as well as around the ,

strOld = "0000000,1111111,2222222,3333333"
arrString = Split(strOld, ",")
For i=0 to UBound(arrString)
      if i= 0 then
            strNew = "'" & arrString(i) & "','"
      elseif i = UBound(arrString) then
            strNew = strNew & arrString(i) & "'"
      else
            strNew = strNew & arrString(i) & "','"
      end if
Next

msgbox strNew
0
 
LVL 5

Accepted Solution

by:
kumar_jac earned 250 total points
ID: 17964781


Hi,
  You can achive this in ONE line as follows.

just copy and paste this

string a = "0000000,1111111,2222222,3333333"
   
 a = "'" + a.replace("," ,"','")   + "'"



0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now