string

How to modify Levenshteins Edit Distance to count "adjacent letter exchanges" as 1 edit

I'm playing around with Levenshteins Edit Distance algorithm, and I want to extend this to count transpositions -- that is, exchanges of adjacent letters -- as 1 edit. The unmodified algorithm counts insertions, deletes or substitutions needed to reach a certain string from another. For instance, the edit distance from "KITTEN" to "SITTI...

How to compare two strings and replacing different bit with - in another string

for example i have two strings 0000 and 0001 then 0000 0001 ---- result= 000- here difference is indicated by - sign ...

Find and replace variable in Ruby string

Let's say I have a string like so: "Lorem ipsum de color [post]57[/post] sit amet [post]103[/post] desectator." I want to find all occurrences of [post]*[/post] and replace it with the title of the post represented by the number. I'd end up with something like so: "Lorem ipsum de color Angry Turtle sit amet Fuzzy Rabit dese...

C++: Elegant way to split string and stuff contents into std::vector

I would like to split a string along whitespaces, and I know that the tokens represent valid integers. I would like to transform the tokens into integers and populate a vector with them. I could use boost::split, make a vector of token strings, then use std::transform. What is your solution? Using boost is acceptable. ...

Preventing keys of different hash values from landing in same bucket with unordered_set

This might be a silly question, but here goes : I hashed a dictionary of words into an unordered_set based hash-table. My hash function was made intentionally "bad", in that all strings that contained the same set of letters would hash to the same value. I initially tried to over-ride the normal hash function behaviour, and use a "freq...

In Python, how would you write a regex that matches the following?

The string contains one or more "@" symbols. One or more of those symbols must have a character after it (not a space). ...

How do I get these values from a string?

The webservice returns the following string "ID: xxxx Status: yyyy" How do I get the value ID value without the "ID :" text, and "Status" value without the "Status: " text. Id value should be xxxx Status value should be yyyy the value length is unknown. ...

Get values from string?

How to get the error number and error description from this string s = "ERR: 100, out of credit"; error should equal "100" error description should equal "out of credit" ...

Check if a variable is a string

Hi there, I am currently using the isNaN function to check if my variable is a string or an object. I just wondered if this is the wrong way of doing it because it does not seem to be working. if(isNaN(element)) element = document.querySelector(element); At the moment even if element is an object it is still causing isNaN to retur...

How to set named argument for string.Format ?

I have C# error when calling: string.Format(format:"abbccc", 1,22); The error is "Named argument specifications must appear after all fixed arguments have been specified" How can I fix this? [Edit] I prefer to use named parameters. ...

OWL: restrict property value to a numeric string

In my database I have things with string properties. Some of the property values match numeric strings (only contain digits). I'd like to give these things a special type (a subtype of what they are). Is such a thing possible in OWL? ...

Regular Expression - extract digits

I have strings of text that may have the following formats: Was £39.95 Now Only £29.00 OR Was 0.95p Now 10p What is the easiest way to extract two numbers from each string, so I can subtract them later. ...

how to pass a substring without actually creating an temporary object in c++

Lets say I have a function str_rev(string &s, int len) {} which reverses the string s of length len I want to reverse a substring of long string starting at index 5 and of length 10 for this I was forced to first call substring function and then call the str_rev function passing the substring sub_string = long_str.substr(5, 10) st...

How to concisely create a String that begins with a primitive value without using an empty double-quote?

To get a newString value of "99 bottles": int x = 99; String fruit = " bottles"; To form a new String I do this: String newString = "" + x + fruit; since this is not allowed: String newString = x + fruit; But there's something about using the double quotes here that doesn't seem right. Is there a better way to do this (without ...

Need to send two kinds of quotes in a string via jQuery

I'm sending some html via jQuery, and in this html are various values that need to be quoted, and in one instance, there's a nested value, so I have to be able to send both kinds of quotes. Here's some mock code: var myVar = "<tag value='foo' value2="config={'bar':null, 'foo2':true}" />"; How can in ensure that the double quotes are s...

String Compare problems? C

Ok so im having a bit of an issue here. basically Im reading shared memory but thats not the problem. I have a change.c function that lets me change a struct studentdata shared memory if I enter their "ID" number. ISSUE WAS SOLVED ...

string conversion

Hi there, I’ve got a long string object which has been formatted like this myString = “[name = john, family = candy, age = 72],[ name = jeff, family = Thomson, age = 24]” of course the string is longer than this. Also i have 3 lists with related names: Names = [] Families = [] Ages = [] I want to read that string character b...

How do I run through an array where the first array member is a string that needs to be split.

I have an array {{".txt|.doc|.docx", "100000"}, {".xls|.xlsx|.xxx" , "10000"}, ".npp", "100000"} I am trying to find a way to run a foreach loop on each member of the array in a loop while also checking the first member as a string not an array. The code will search for all docs greater than 10000 bytes, as long as the docs are txt, do...

Chaining string methods (split, gsub) in Ruby

I'd like to split and do a substitution in a string in one chained command. Here's my example including the error message: >> filebase => "Ueki_-_Hello_World" >> filebase.split("_-_").gsub("_"," ") NoMethodError: private method `gsub' called for ["Ueki", "Hello_World"]:Array from (irb):16 It works when I save the result of "split...

Find a string pattern in a set of strings

I have a set of strings, set<string>, and a string to check, I would like to do a binary search over it, obviously, a set is sorted. The purpose is to find the longer string in the set that is contained in the supplied string to check. It's basically to check for urls and registered handlers. I'm digging in the std algorithms and com...