replace

How can I replace a character in a string with something else?

风格不统一 提交于 2020-01-06 05:25:16
问题 I'm making a program. Now to write the data in the file I need to replace the spaces in the string obtained with lets say a # symbol. Is there any command in C# that lets me do this without looping through the whole string? 回答1: Sure, use the Replace() method. s = s.Replace(" ", "#"); (And if you want people here to want to help you in the future, my recommendation would be to start accepting some answers. Just a thought.) 回答2: To replace # with text string s = "test # again"; s = s.Replace("

jquery remove part of url

自作多情 提交于 2020-01-06 04:52:47
问题 Lets say i've got the following url; http://www.domain.com/en-US/assortment/en-US/category/page.aspx?sub=GROUP7 As you can see I have two language layers in the url from which I want to remove ONLY the second one. So I expect the url to be like this. http://www.domain.com/en-US/assortment/category/page.aspx?sub=GROUP7 Due to technical limitations I don't have any other ways to modify the url. Can this be achieved with jQuery or Javascript? If yes, how? 回答1: 'your url here...'.replace( '

replace new lines with “” in C#

两盒软妹~` 提交于 2020-01-06 04:19:28
问题 I want to convert this: <translation> 1 Sənədlər </translation> to <translation>1 Sənədlər</translation> in XML using C#. Please help me. Only translation tags. I tried this: XDocument xdoc = XDocument.Load(path); xdoc.Save("path, SaveOptions.DisableFormatting); But it does not remove the new lines between <translation> tags. 回答1: A new line is determined in the code by " \n " and possibly also " \r ". You can simply remove these: string xmlString = "<translation>\r\n1 Sənədlər\r\n<

Remove quotes from quoted string using regex

懵懂的女人 提交于 2020-01-06 03:22:08
问题 I have a string like FVAL(XXX)="TRUE" AND FVAL(TT)="FALSE" I want to replace all "TRUE" and "FALSE" by TRUE AND FALSE . Now the resultant string should be FVAL(XXX)=TRUE AND FVAL(TT)=FALSE Will the code shown below be upto the mark for this. Regex.Replace("FVAL(XXX)=""TRUE"" AND FVAL(TT)=""FALSE""", "[""]TRUE[""]", "TRUE", RegexOptions.IgnoreCase) Note: Now I know you guys would say that this is not a constructive question and should be closed, but the reason I asked this is because what I

PHP or Javascript: Simply Remove and Replace HTML Code

二次信任 提交于 2020-01-06 03:11:13
问题 I have this code on my page, but the link has different names and ids: <div class="myclass"> <a href="http://www.example.com/?vstid=00575000&veranstaltung=http://www.example.com/page.html"> Example Text</a> </div> how can I remove and Replace it to this: <div class="myclass">Sorry no link</div> With PHP or Javascript? I tried it with str.replace Thank you! 回答1: I assume you mean dynamically? You won't be able to do this with php because it is server side, and doesn't have anything to do with

How to do the smallest match in regex replace even if the editor does not support non-greedy match

纵饮孤独 提交于 2020-01-05 18:55:18
问题 I using regex search to replace the following string: \new{}\new{\textbf{test1}}\new{test2} with \textbf{test1}test2 I used regex replace with \new{(.*)} to find and \1 to replace. however the search always match the whole line of my original string and the replace reuslt is: }\new{\textbf{test1}}\new{test2 far from what I need. In regex expression in Java, you can use a ? after a quantifier makes it a reluctant quantifier. It then tries to find the smallest match. So in java, my search regex

Find special markers in sequence and do something to the text in between

非 Y 不嫁゛ 提交于 2020-01-05 12:28:53
问题 I wanna do something that would work much like this shortcode in stackexchange. So basically I want to wrap text with distinct markers and .wrap() them in spans with specific classes accordingly... while also removing the markers that once existed. I found this Find Text Between 2 Quotes with jQuery but it gives little help as i could only make it work as it was. This explains a little further: http://jsfiddle.net/ALfsT/3/ I have no idea where to go with this. 回答1: Thanks @Guffa for the help

How can I replace specific word in c# with parenthesis?

时光总嘲笑我的痴心妄想 提交于 2020-01-05 12:14:12
问题 Consider the following string: string s = "The man is (old)."; If I use: Regex.Replace(s,@"\b\(old\)\b", @"<b>$&</b>"); The output is : The man is (old). But I would change the whole of the (old) word like this: The man is (old) . How can I do this? 回答1: \b won't match because ( and ) are not word characters. Is there a reason why you put them there, because you could just leave them out: string replaced = Regex.Replace(s,@"\(old\)", @"<b>$&</b>"); According to the specs: \b : The match must

How can I replace specific word in c# with parenthesis?

半世苍凉 提交于 2020-01-05 12:14:11
问题 Consider the following string: string s = "The man is (old)."; If I use: Regex.Replace(s,@"\b\(old\)\b", @"<b>$&</b>"); The output is : The man is (old). But I would change the whole of the (old) word like this: The man is (old) . How can I do this? 回答1: \b won't match because ( and ) are not word characters. Is there a reason why you put them there, because you could just leave them out: string replaced = Regex.Replace(s,@"\(old\)", @"<b>$&</b>"); According to the specs: \b : The match must

Java Regex to replace string surrounded by non alphanumeric characters

雨燕双飞 提交于 2020-01-05 12:13:12
问题 I need a way to replace words in sentences so for example, "hi, something". I need to replace it with "hello, something" . str.replaceAll("hi", "hello") gives me "hello, somethellong" . I've also tried str.replaceAll(".*\\W.*" + "hi" + ".*\\W.*", "hello") , which I saw on another solution on here however that doesn't seem to work either. What's the best way to achieve this so I only replace words not surrounded by other alphanumeric characters? 回答1: Word boundaries should serve you well in