[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2012-04-11
5
Medium Priority
?
501 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
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…

649 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