[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ASP.NET / VB / REGEX: Convert dashes to bullets if at beginning of line

Posted on 2012-04-11
5
Medium Priority
?
502 Views
Last Modified: 2012-06-27
I want to replace a dash with a bullet if it is at the beginning of a line.

The problem with my code is that it does not work on the first line.  It works for all lines except the first line.

This:
- Hello world
- This is a test
- Item XYZ

Should become this:
• Hello world
• This is a test
• Item XYZ

 
input = RegularExpressions.Regex.Replace(input, VbNewLine + "- ", VbNewLine + "• ")

Open in new window

0
Comment
Question by:hankknight
  • 3
5 Comments
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 664 total points
ID: 37835408
Its bacause you have "VbNewLine" in the expression.
0
 
LVL 6

Assisted Solution

by:yawkey13
yawkey13 earned 672 total points
ID: 37835431
Regex.Replace(input, "^- ", "• ") will get the first one.  The easiest would be to just call both.

input = RegularExpressions.Regex.Replace(input, "^- ", "• ") ;
input = RegularExpressions.Regex.Replace(input, VbNewLine + "- ", VbNewLine + "• ");
0
 
LVL 8

Expert Comment

by:PagodNaUtak
ID: 37835450
The reason why it does not work in the first line is becuase the first does not contain any carriage return or new line. Your code replaces only the character that is VbNewLine with "- ". As a work around append try the below code:

Approach one:
input = "•" + RegularExpressions.Regex.Replace(input, VbNewLine + "- ", VbNewLine + "• ")

Open in new window


Approach two:
input = string.Format("{0}{1} {2},"VbNewLine, "-", input)
input = RegularExpressions.Regex.Replace(input, VbNewLine + "- ", VbNewLine + "• ")
0
 
LVL 8

Expert Comment

by:PagodNaUtak
ID: 37835453
Typo erro, approach two should be like this:

Approach two:
input = string.Format("{0}{1} {2}"VbNewLine, "-", input)
input = RegularExpressions.Regex.Replace(input, VbNewLine + "- ", VbNewLine + "• ")
0
 
LVL 8

Accepted Solution

by:
PagodNaUtak earned 664 total points
ID: 37835457
Typo error, approach two should be like this:

Approach two:
input = string.Format("{0}{1} {2}", VbNewLine, "-", input)
input = RegularExpressions.Regex.Replace(input, VbNewLine + "- ", VbNewLine + "• ")
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

873 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