string-manipulation

How to calculate the percentage of similarity or difference between two texts / strings ?

Explaining it further Assume i have two strings like below I am a super boy who can Fly! Really . I am super boy who can Break walls! Really . So some characters are similar I am super boy who can and Really . . Is there anything ready to use to find percentage similarity/diffrence between those two strings. ...

How do I change all empty strings to NULL in a table

I have a legacy table with about 100 columns (90% nullable). In those 90 columns I want to remove all empty strings and set them to null. I know I can: update table set column = NULL where column = ''; update table set column2 = NULL where column2 = ''; But that is tedious and error prone. There has to be a way to do this on the whole...

ksh-style left and right string stripping up to matched expression?

How can one strip the left parts and right parts off strings up to a matching expression as in ksh? For instance: ${name##*/} ${name%/*} (see http://www.well.ox.ac.uk/~johnb/comp/unix/ksh.html for ksh examples). I can't seem to figure out a simple way of doing this using re module or string module but I must be missing something. ...

SQL / Wordpress - query for removing a comment field

Hi Does anyone know how can I replace the "comment_author_url" field from all comments by running a SQL query? for example if this field is http://google.com to replace it with "" (empty string) ...

How to remove special characters and letters from a line read from a text file in Python?

How can I remove special characters and letters from a line read from a text file while preserving the whitespaces? Let's say we have the following contents in a file: 16 ` C38# 26535 2010 4 14 2 7 7 3 8^@1 2 15 100 140 30 $ 14^] (2003 2 ! -6 �021 0 � 14 ! 2 3! 1 0 35454 ...

How to get the last characters in a String in Java, regardless of String size.

Hi, I'm looking for a way to pull the last characters from a String, regardless of size. Lets take these strings into example: "abcd: efg: 1006746" "bhddy: nshhf36: 1006754" "hfquv: nd: 5894254" As you can see, completely random strings, but they have 7 numbers at the end. How would I be able to take those 7 numbers? Edit: I just r...

php/regex: "linkify" blog titles

I'm trying to write a simple PHP function that can take a string like Topic: Some stuff, Maybe some more, it's my stuff? and return topic-some-stuff-maybe-some-more-its-my-stuff As such: lowercase remove all non-alphanumeric non-space characters replace all spaces (or groups of spaces) with hyphens Can I do this with a single reg...

c# string Trim doesn't work, a weird problem

Hi, I have string like that: string val = 555*324-000 now, I need to remove * and - chars, so I use that code (based on MSDN) char[] CharsToDelete = {'*', '(', ')', '-', '[', ']', '{', '}' }; string result = val.Trim(CharsToDelete); but the string remains the same. What's the reason ? ...

How do i select a character in a textfield?

is it possible to select a certain character from a textfield ? Is it possible to switch their position as well? e.g. Hello is it possible to switch the position of the "H" with the "e" ? to make it "eHllo" ? ...

What is the difference between string.find and string.match in Lua?

I am trying to understand what the difference is between string.find and string.match in Lua. To me it seems that both find a pattern in a string. But what is the difference? And how do I use each? Say, if I had the string "Disk Space: 3000 kB" and I wanted to extract the '3000' out of it. EDIT: Ok, I think I overcomplicated things and ...

php code to check for repeating characters / bogus text

hi there, i'm running a dating site and there is a place where people enter their profile - I already have a bad-words filter but now I have a problem where people enter a profile that is just garbage characters or just "aaaaaaaaaaaaaaaaaaaa" or "--------------" etc. I'm looking for an effective way of filtering out the long words of rep...

PHP Calculations inside string creation

I want to to create a string in php, but within the creation of the string I want to do a small calculation, here is an example of what I am trying but does not work. $eggs = 2; $breakfast = 'I ate '. $eggs-1 . ' eggs for breakfast today!'; Using PHP like this gives me a unexpected T_CONSTANT_ENCAPSED_STRING error. ...

Regular expressions in Lua using .gsub()

Ok, I think I overcomplicated things and now I'm lost. Basically, I need to translate this, from Perl to Lua: my $mem; my $memfree; open(FILE, 'proc/meminfo'); while (<FILE>) { if (m/MemTotal/) { $mem = $_; $mem =~ s/.*:(.*)/$1/; } } close(FILE); So far I've written this: for Line in io.lines("/proc/memin...

C# String splitting - breaking string up at second comma

Hi I have a string like so: mystring = "test1, 1, anotherstring, 5, yetanother, 400"; myarray can be of varying length. What I would like to do is split the string up like so: {"test1, 1"} {"anotherstring, 5} {"yetanother, 400"} Is this possible? I tried string[] newArray = mystring.Split(',') but that splits it at every comma, a...

English Sentence to Camel-cased method name

I had to convert a series of sentences into camel-cased method names. I ended writing something for it. I am still curious if there's something simpler for it. Given the string a = "This is a test." output thisIsATest I used for following: a.downcase.gsub(/\s\w/){|b| b[-1,1].upcase } ...

How to construct a comma-separated string in Bourne shell?

Hello, I'm not sure how to do this but I figured I would ask here.. I'm trying to create a string of specific environment variables such that: $A = "foo" $B = "bar" $C = "baz" would give "foo, bar, baz" Unfortunately, it doesn't seem that the Bourne shell supports arrays, which would have made these easily solvable. The other way I'm...

Is there a multiple character version of strchr() in the standard C libraries?

In c if I wanted to search a string for a particular character I can just do the following char *p; p = (char *)strchr(buffer,'('); if(p){ .... but what if I want to search for more than one character (or a character range) for example "any digit". I know I could do something like char *p=0; char *i; for(i=buffer;*i!='\0';i++){ ...

Pythonic way to insert every 2 elements in a string

Is there a pythonic way to insert an element into every 2nd element in a string? I have a string: 'aabbccdd' and I want the end result to be 'aa-bb-cc-dd'. I am not sure how I would go about doing that. ...

Segmentation Fault with strcat

Hi, I'm having a bit of a problem with strcat and segmentation faults. The error is as follows: Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000 0x00007fff82049f1f in __strcat_chk () (gdb) where #0 0x00007fff82049f1f in __strcat_chk () #1 0x0000000100000adf i...

BASH: Split MAC Address -> 000E0C7F6676 to 00:0E:0C:7F:66:76

Hy, Can someone help me with splitting mac addresses from a log file? :-) This: 000E0C7F6676 should be: 00:0E:0C:7F:66:76 Atm i split this with OpenOffice but with over 200 MAC Address' this is very boring and slow... It would be nice if the solution is in bash. :-) Thanks in advance. ...