replace

XSLT for replace attribute in XML element if it exists in another XML?

倖福魔咒の 提交于 2020-01-11 06:25:29
问题 I have 2 files catalog.xml <?xml version="1.0" encoding="UTF-8"?> <catalog> <CD Title="Still got the blues" vinyl="unknown"/> <CD Title="When a man loves a woman" vinyl="unknown"/> </catalog> vinyl.xml <?xml version="1.0" encoding="UTF-8"?> <Vinyl> <Album> <Title>When a man loves a woman</Title> <Vinyl>Yes</Vinyl> </Album> </Vinyl> How to produce such output.xml with xslt? <?xml version="1.0" encoding="UTF-8"?> <catalog> <CD Title="Still got the blues" vinyl="unknown"/> <CD Title="When a man

Using Regex.Replace to keep characters that can be vary

故事扮演 提交于 2020-01-11 05:42:12
问题 I have the following: string text = "version=\"1,0\""; I want to replace the comma for a dot , while keeping the 1 and 0, BUT keeping in mind that they be different in different situations! It could be version="2,3" . The smart ass and noob-unworking way to do it would be: for (int i = 0; i <= 9; i++) { for (int z = 0; z <= 9; z++) { text = Regex.Replace(text, "version=\"i,z\"", "version=\"i.z\""); } } But of course.. it's a string, and I dont want i and z be behave as a string in there. I

Complement a DNA sequence

萝らか妹 提交于 2020-01-10 19:33:27
问题 Suppose I have a DNA sequence. I want to get the complement of it. I used the following code but I am not getting it. What am I doing wrong ? s=readline() ATCTCGGCGCGCATCGCGTACGCTACTAGC p=unlist(strsplit(s,"")) h=rep("N",nchar(s)) unlist(lapply(p,function(d){ for b in (1:nchar(s)) { if (p[b]=="A") h[b]="T" if (p[b]=="T") h[b]="A" if (p[b]=="G") h[b]="C" if (p[b]=="C") h[b]="G" } 回答1: Use chartr which is built for this purpose: > s [1] "ATCTCGGCGCGCATCGCGTACGCTACTAGC" > chartr("ATGC","TACG",s)

Find and Replace for an Textarea

泄露秘密 提交于 2020-01-10 13:17:24
问题 Would anyone have any idea how to make a Find and Replace thing where when you can just click next it will bring you to the next found item? Edit: For an Textarea. I want a Javascript code that can add a Find and Replace to Textarea. I don't wanna just use. search() or Replace(). At the Moment im trying this: function allIndexes() { var indices = new Array(); var index = 0; var i = 0; while(index = $('#text').val().indexOf($('#search').val(), index) > 0) { indices[i] = index; i++; } return

Find comma in quotes with regex and replace with HTML equiv

放肆的年华 提交于 2020-01-10 05:32:06
问题 I'm looking in a string such as: "Hello, Tim" Land of the free, and home of the brave And I need it to become: "Hello, Tim" Land of the free, and home of the brave This I thought was simple, but for the life of me I can't figure it out. Im importing a corrupt CSV with 1000s of entries via AJAX, so I just need to convert commas INSIDE of double quotes. How would I go about do this with JavaScript? I can't figure it out. I tried 回答1: var str = '"Hello, Tim"\n\ \n\ Land of the free, and home of

Replace substring in PowerShell

 ̄綄美尐妖づ 提交于 2020-01-10 04:48:07
问题 I have a string in the form -content- , and I would like to replace it with &content& . How can I do this with replace in PowerShell? 回答1: The built-in -replace operator allows you to use a regex for this e.g.: C:\PS> '-content-' -replace '-([^-]+)-', '&$1&' &content& Note the use of single quotes is essential on the replacement string so PowerShell doesn't interpret the $1 capture group. 回答2: PowerShell strings are just .NET strings, so you can: PS> $x = '-foo-' PS> $x.Replace('-', '&') &foo

Regex- replace sequence of one character with same number of another character

丶灬走出姿态 提交于 2020-01-10 03:37:12
问题 Let's say I have a string like this: ===== and I want to replace it with this: ----- I only want to replace it if it has more than a certain number of that character (we'll say > 3). So, these should be the replacements: === -> === ==== -> ---- ===== -> ----- The application is I want to replace all level 1 heading marks in markdown with a level 2 mark, without changing embedded code blocks. I know I can do this: /=/-/g , but this matches anything with an equals sign ( if (x == y) ), which is

python 爬虫1

℡╲_俬逩灬. 提交于 2020-01-09 23:17:22
#库的准备 import requests #cmd pip install requests安装 import re #系统库 #下载网址 url = 'https://www.shujy.com/5200/9613/' #发送http请求,及响应 #加headers,不加容易报403,防爬虫 headers = { "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0" ,} response = requests.get(url, headers = headers) #向url发送请求 #编码方式 response.encoding = 'utf-8' #目标主页源码 html=response.text #小说名 title = re.findall( r '<meta property="og:novel:book_name" content=" ( . *? ) "/>' ,html) #print(title) #新建文本保存 ,%s与%d一样 'w'代表以写的方式打开,以utf-8方式编码 fb = open ( ' %s .txt' % title, 'w' , encoding = 'utf-8' ) #print

Efficiently replace values from a column to another column Pandas DataFrame

若如初见. 提交于 2020-01-09 19:07:10
问题 I have a Pandas DataFrame like the following one: col1 col2 col3 1 0.2 0.3 0.3 2 0.2 0.3 0.3 3 0 0.4 0.4 4 0 0 0.3 5 0 0 0 6 0.1 0.4 0.4 I want to replace the col1 values with the values in the second column ( col2 ) only if col1 values are equal to 0, and after (for the zero values remaining), do it again but with the third column ( col3 ). The Desired Result is the next one: col1 col2 col3 1 0.2 0.3 0.3 2 0.2 0.3 0.3 3 0.4 0.4 0.4 4 0.3 0 0.3 5 0 0 0 6 0.1 0.4 0.4 I did it using the pd

Efficiently replace values from a column to another column Pandas DataFrame

落花浮王杯 提交于 2020-01-09 19:06:35
问题 I have a Pandas DataFrame like the following one: col1 col2 col3 1 0.2 0.3 0.3 2 0.2 0.3 0.3 3 0 0.4 0.4 4 0 0 0.3 5 0 0 0 6 0.1 0.4 0.4 I want to replace the col1 values with the values in the second column ( col2 ) only if col1 values are equal to 0, and after (for the zero values remaining), do it again but with the third column ( col3 ). The Desired Result is the next one: col1 col2 col3 1 0.2 0.3 0.3 2 0.2 0.3 0.3 3 0.4 0.4 0.4 4 0.3 0 0.3 5 0 0 0 6 0.1 0.4 0.4 I did it using the pd