Jump to content

string help with "

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
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?
Its only funny till someone gets hurt.... THEN ITS HILARIOUS :)

#2
semprance

semprance

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
Maybe you need to escape the character

\"


#3
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts

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.

#4
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
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
Its only funny till someone gets hurt.... THEN ITS HILARIOUS :)

#5
JayDee01

JayDee01

    Newbie

  • Members
  • Pip
  • 1 posts
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.

#6
semprance

semprance

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
If you use Regex.Replace you can replace a pattern so you could have something like:

    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
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
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
Its only funny till someone gets hurt.... THEN ITS HILARIOUS :)

#8
semprance

semprance

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
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'.