string

Regex match a string with spaces (use quotes?) in an if statement

How would I do a regex match as shown below but with quotes around the ("^This") as in the real world "This" will be a string that can have spaces in it. #!/bin/bash text="This is just a test string" if [[ "$text" =~ ^This ]]; then echo "matched" else echo "not matched" fi I want to do something like if [[ "$text" =~ "^This ...

How to return a Ruby array intersection with duplicate elements? (problem with bigrams in Dice Coefficient)

Hi there I'm trying to script Dice's Coefficient, but I'm having a bit of a problem with the array intersection. def bigram(string) string.downcase! bgarray=[] bgstring="%"+string+"#" bgslength = bgstring.length 0.upto(bgslength-2) do |i| bgarray << bgstring[i,2] end return bgarray end def approx_string_match(test...

Putting strings into a 2D chararray in C.

How do I put strings into an 2D char array from (for example) a file? char buffert[10][30]; int i = 0; while(!feof(somefile)) { fscanf(somefile, "%s", temp); buffert[i][] = temp; i++; } This will not do it. ...

Discard Chars After Space In C# String

I would like to discard the remaining characters (which can be any characters) in my string after I encounter a space. Eg. I would like the string "10 1/2" to become "10"; Currently I'm using Split, but this seems like overkill: string TrimMe = "10 1/2"; string[] cleaned = TrimMe.Split(new char[] {' '}); return string[0]; I feel the...

Please explain this behavior with character arrays/strings in C

I get this when I was trying something (just for understanding). Please explain this behavior: First attempt: void main() { char src[] = "vinay"; int i; // char name[5] = "test"; char *name= "abcde"; printf("%s \n", name); if (*(name+5) == '\0') printf("6th char is null\n"); strcpy(name,src...

strcpy when dest buffer is smaller than src buffer

I am trying to understand the difference/disadvantages of strcpy and strncpy. Can somebody please help: void main() { char src[] = "this is a long string"; char dest[5]; strcpy(dest,src) ; printf("%s \n", dest); printf("%s \n", src); } The output is: this is a long string a long string QUESTION: I dont understand, how the sou...

In C++, how can a class take a const std::string& parameter in the constructor but also handle NULL?

I'm trying to work through ways to create a class with a std::string argument, but which also handles NULL without throwing an exception. Here's an example of the code: class myString { public: myString(const std::string& str) : _str(str) {} std::string _str; }; int main() { myString mystr(NULL); printf("mystr = <%s>\n...

Smalltalk - Converting text object to string

Hi I have text editor widget in smalltalk (visual works) that returns a text object, however I want the text returned to be handled as a string object. How do you parse a text object as a string? ...

Parsing a text file with Python?

Hello, I have to do an assignment where i have a .txt file that contains something like this p There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain... h1 this is another example of what this text file looks like i am suppose to write a python code that parses this text file and c...

Verify Text of item in Listbox is the same one in List<string> C#

I'm trying to get it to verify that it has the same item in the List as the one that's currently selected in the listbox Why does this code not work, It should work unconditionally because the text generated from the listbox is taken from the List choicetitle if (RemovePackages_Listbox.Text == choicetitle[RemovePackages_Listbox.Selecte...

PHP - Getting rid of curly apostrophes

I'm trying to get rid of curly apostrophes (ones pasted from some sort of rich text doc, I imagine) and I seem to be hitting a road block. The code below isn't working for me. $word = "Today’s"; $search = array('&#8222;', '&#8220;', '&#146;'); $replace = array('"', '"', "'"); $word = str_replace($search, $replace, htmlentities($word, E...

Efficient way of calculating likeness scores of strings when sample size is large?

Let's say that you have a list of 10,000 email addresses, and you'd like to find what some of the closest "neighbors" in this list are - defined as email addresses that are suspiciously close to other email addresses in your list. I'm aware of how to calculate the Levenshtein distance between two strings (thanks to this question), which...

PHP inserting ellipsis in the middle(!) of a string?

I am working on a PHP forum software (FluxBB) and a user encountered a rather interesting error, that - so it seems - PHP is inserting an ellipsis in the middle of a string. Due to a similar error I found on the net I feel forced to say that this code is situated in a function and that $db is a global variable. Here's the (simplified) ...

Why do floats having trailing .0 when it is exactly an integer?

Read this question carefully because I am not asking how to get rid of trailing zeros, that's easy. What I am asking is why does 123d become "123.0"? A IEEE 64-bit float can represent integers from 0 to 2^52 exactly, so this isn't a loss in precision but a decision during the implementation of Double.toString(). My question is why did...

jquery to goto a url on form submit with field values added to the url string

Hi All, I'm fairly new to jquery and I think this is simple but I'm struggling and google doesn't seem to be helping.... What I have is a basic form... <form> First Name: < input type="text" name="firstName" id="firstName" /> Surname: < input type="text" name="surname" id="surname" /> <input type="submit" id="submit" value="submit"/> ...

array component with string keys

About two years ago I have found a component that can be used to create array with string keys on delphi... anyone know a component like this?? ...

String concatenation vs String Builder. Performance

I have a situation where I need to concatenate several string to form an id of a class. Basically I'm just looping in a list to get the ToString values of the objects and then concatenating them. foreach (MyObject o in myList) result += o.ToString(); The list is NOT expected to have more than 5 elements (although it could but that's...

Help me delete the last three chars of any string please!

Test string: the%20matrix%20 How can I delete the last three chars? Using this code gives me an out of index exception: y = y.Substring(y.Length - 4, y.Length - 1); ...

Truncate string on whole words in .Net C#

Hi, I am trying to truncate some long text in C#, but I don't want my string to be cut off part way through a word. Does anyone have a function that I can use to truncate my string at the end of a word? E.g: "This was a long string..." Not: "This was a long st..." Thanks, Tim ...

String prototype modifying itself

As far as i know it's not possible to modify an object from itself this way: String.prototype.append = function(val){ this = this + val; } So is it not possible at all to let a string function modify itself? ...