Hello,
i am trying to put this into a string like this:
string s = ("\ >)(.*?)(href=)
however because of the " it wont work, how can i include it though, its very important for the regex match i need. any idea?
string help with "
Started by Siten0308, Apr 20 2010 10:37 AM
7 replies to this topic
#1
Posted 20 April 2010 - 10:37 AM
Its only funny till someone gets hurt.... THEN ITS HILARIOUS :)
|
|
|
#2
Posted 20 April 2010 - 03:29 PM
Maybe you need to escape the character
\"
#3
Posted 20 April 2010 - 04:47 PM
Quote
Maybe you need to escape the character
\"
semprance is correct if you want to include any special letter in regex you must escape it with \ character.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
#4
Posted 20 April 2010 - 09:32 PM
thanks for all the replies,
I had one more question in regards to string,
what if i had like
<something here, that needs to be removed>>
and lets say i want to remove characters < , and >> could i use string.trim()? or string.replace? what if i want to remove multiple character without having to keep on doing,
string.trim(>)
string.trim(,)
etc.
etc
but just knock it all out with string.trim(>, and >>) anyway how??
thanks
I had one more question in regards to string,
what if i had like
<something here, that needs to be removed>>
and lets say i want to remove characters < , and >> could i use string.trim()? or string.replace? what if i want to remove multiple character without having to keep on doing,
string.trim(>)
string.trim(,)
etc.
etc
but just knock it all out with string.trim(>, and >>) anyway how??
thanks
Its only funny till someone gets hurt.... THEN ITS HILARIOUS :)
#5
Posted 21 April 2010 - 01:41 AM
Hello
If you like to remove certain characters from a string i would use string.replace().
In your example it would be something like this: string.replace(">", "")
Between the first " " you put the character(s) you want to replace or remove, and between the last " " you put what you want to replace it with, in this case nothing.
All > characters in the string will be removed.
I hope this answer is usefull.
If you like to remove certain characters from a string i would use string.replace().
In your example it would be something like this: string.replace(">", "")
Between the first " " you put the character(s) you want to replace or remove, and between the last " " you put what you want to replace it with, in this case nothing.
All > characters in the string will be removed.
I hope this answer is usefull.
#6
Posted 21 April 2010 - 02:52 AM
If you use Regex.Replace you can replace a pattern so you could have something like:
It's something like that, I can't remember exactly. Also you might have to escape the angle brackets. Check out this cheatsheet for tips:
C# Regular Expressions Cheat Sheet
Regex.Replace(myString, "[>|>>|<|<<]");
It's something like that, I can't remember exactly. Also you might have to escape the angle brackets. Check out this cheatsheet for tips:
C# Regular Expressions Cheat Sheet
#7
Posted 21 April 2010 - 12:13 PM
awesome thanks again semprance, i also wanted to ask one last question sorry, this is easy but not sure how to do it,
lets say i have a sentance string
string sentance = "this is a sentance and needs to be split";
and i want to split it at the 4th word and put it in the next line, is there any way how to do that? so its like
string sentance = "this is a sentance\n and needs to be split";
i shouldnt say split, but code wise, is there a way to put a string sentence if over 4 words put a \n so it goes into the next line?
thanks
lets say i have a sentance string
string sentance = "this is a sentance and needs to be split";
and i want to split it at the 4th word and put it in the next line, is there any way how to do that? so its like
string sentance = "this is a sentance\n and needs to be split";
i shouldnt say split, but code wise, is there a way to put a string sentence if over 4 words put a \n so it goes into the next line?
thanks
Its only funny till someone gets hurt.... THEN ITS HILARIOUS :)
#8
Posted 21 April 2010 - 01:15 PM
You could loop through the string and every time you encounter a space (eg. myString[i] = " ") increase a counter. Then, when the counter hits 4, insert a "\n" at index 'i'.


Sign In
Create Account


Back to top









