string-substitution

How can I compare two strings to find the number of characters that match in R, using substitution distance?

感情迁移 提交于 2021-02-18 11:37:30
问题 In R, I have two character vectors, a and b. a <- c("abcdefg", "hijklmnop", "qrstuvwxyz") b <- c("abXdeXg", "hiXklXnoX", "Xrstuvwxyz") I want a function that counts the character mismatches between each element of a and the corresponding element of b. Using the example above, such a function should return c(2,3,1) . There is no need to align the strings. I need to compare each pair of strings character-by-character and count matches and/or mismatches in each pair. Does any such function exist

How to replace \r\n characters in a text string specifically in R

房东的猫 提交于 2021-02-11 14:38:33
问题 For the life of me, I am unable to strip out some escape characters from a text string (prior to further processing). I've tried stringi, gsub, but I just cannot get the correct syntax. Here is my text string txt <- "c(\"\\r\\n Stuff from a webpage: That I scraped using webcrawler\\r\\n\", \"\\r\\n \", \"\\r\\n \", \"\\r\\n \", \"\\r\\n\\r\\n \", \"\\r\\n\\r\\n \", \"\\r\\n \\r\\n \", \"\\r\\n \")" I'd like to strip out "\\r\\n" from this string. I've tried gsub("[\\\r\\\n]", "", txt) (leaves

Replace a substring in Lua with a pattern

我是研究僧i 提交于 2021-01-28 03:03:10
问题 I have a string like this str = '["username"] = "user"; ["deepscan"] = "true"; ["token"] = true; ["password"] = "krghfkghkfghf"; ["uploadMethod"] = "JSON"; ["serviceIsRunning"] = {}; ["host"] = "sample.com"; ["instance_ID"] = 405454058;' I would like the pattern match ["password"] = and have it replace only the string in between the ";' that would be '"krghfkghkfghf" in this instance. 回答1: local function replacePass(configstr, newpass) return configstr:gsub("(%[\"password\"%]%s*=%s*)%b\"\"",

Replace a substring in Lua with a pattern

喜夏-厌秋 提交于 2021-01-28 00:34:05
问题 I have a string like this str = '["username"] = "user"; ["deepscan"] = "true"; ["token"] = true; ["password"] = "krghfkghkfghf"; ["uploadMethod"] = "JSON"; ["serviceIsRunning"] = {}; ["host"] = "sample.com"; ["instance_ID"] = 405454058;' I would like the pattern match ["password"] = and have it replace only the string in between the ";' that would be '"krghfkghkfghf" in this instance. 回答1: local function replacePass(configstr, newpass) return configstr:gsub("(%[\"password\"%]%s*=%s*)%b\"\"",

JQ: How to multiply values that are recognised as strings?

℡╲_俬逩灬. 提交于 2020-01-13 19:24:26
问题 I am trying to get some trade information from an exchange websocket. Both values .p and .q are enclosed between double quotes in the JSON I get from the socket. When I try to multiply two values, it says I am trying to multiply two strings. So I pass those strings though the tonumber filter and the error message changes a bit, but can't get it to work really. JSON: {"e":"aggTrade","E":1562109562958,"s":"BTCUSDT","a":134343336,"p":"10796.60000000","q":"0.00139000","f":147532295,"l":147532295,

JQ: How to multiply values that are recognised as strings?

安稳与你 提交于 2020-01-13 19:24:06
问题 I am trying to get some trade information from an exchange websocket. Both values .p and .q are enclosed between double quotes in the JSON I get from the socket. When I try to multiply two values, it says I am trying to multiply two strings. So I pass those strings though the tonumber filter and the error message changes a bit, but can't get it to work really. JSON: {"e":"aggTrade","E":1562109562958,"s":"BTCUSDT","a":134343336,"p":"10796.60000000","q":"0.00139000","f":147532295,"l":147532295,

Perl hash substitution with special characters in keys

只谈情不闲聊 提交于 2020-01-11 14:47:28
问题 My current script will take an expression, ex: my $expression = '( a || b || c )'; and go through each boolean combination of inputs using sub/replace, like so: my $keys = join '|', keys %stimhash; $expression =~ s/($keys)\b/$stimhash{$1}/g; So for example expression may hold, ( 0 || 1 || 0 ) This works great. However, I would like to allow the variables (also in %stimhash) to contain a tag, *. my $expression = '( a* || b* || c* )'; Also, printing the keys of the stimhash returns: a*|b*|c* It

Perl hash substitution with special characters in keys

可紊 提交于 2020-01-11 14:47:12
问题 My current script will take an expression, ex: my $expression = '( a || b || c )'; and go through each boolean combination of inputs using sub/replace, like so: my $keys = join '|', keys %stimhash; $expression =~ s/($keys)\b/$stimhash{$1}/g; So for example expression may hold, ( 0 || 1 || 0 ) This works great. However, I would like to allow the variables (also in %stimhash) to contain a tag, *. my $expression = '( a* || b* || c* )'; Also, printing the keys of the stimhash returns: a*|b*|c* It

Change text of an attributed string and retain attributes in Swift

本秂侑毒 提交于 2019-12-23 19:25:05
问题 For output in a database program, I have certain text that I've inserted marks to indicate bold or italics, as well as some text that is substituted for images. For instance: "%Important% ^All employees to the breakroom^" should have final output as: Important All employees to the breakroom I have code written to find the text with "%" signs around it and "^" signs, but the trouble I have now is the text outputs like: %Important% ^ All employees to the breakroom ^ I'd like to remove these %

sed wildcard substitution

独自空忆成欢 提交于 2019-12-21 16:49:21
问题 I want to do a substitution based on a wildcard. For example, change all "tenure" to "disposition" only if the word "tenure" comes after an '=' sign. Basically a regex that would match this =.*tenure The sed command that I have so for this is: sed 's/=.*tenure/=.*disposition/g' file.txt However, if I pass this to a file containing: blah blah blah = change "tenure" to "disposition" I get blah blah blah =.*disposition" to "disposition" instead of: blah blah blah = change "disposition" to