string-manipulation

Python strip a string..

Hi, url = 'abcdc.com' print url.strip('.com') Expect: abcdc Resut: abcd Now I do url.rsplit('.com', 1) Is there a better way.. ...

Parse a string to a specified length (without cutting words)

I have a long string that I need to parse into an array of strings that do not exceed 40 characters in length. The tricky part of this for me is making sure that the regex finds the last whitespace before 40 characters to make a clean break between strings since I don't want words cut off. ...

jQuery string manipulation, regex noob.

First off I don't know much about regex and need to buy a book because it's has proven to me to be difficult to pickup. Ultimately I want to take a dom element, and replace text within straight brackets "[" and "]" and insert a link around the text, and there may be multiple bracket sets in the string. function changeTip() { ...

Parse <br> to plain text new paragraph

I am currently in the process of removing html tags from fields within an internal database. Everything has gone smoothly except for turning tags to plain text new line characters. I would like to convert this: The victory halted Spain&rsquo;s 35-game unbeaten streak, handing the Spanish their first defeat since November 2006. The Ame...

.NET string IndexOf unexpected result

A string variable str contains the following somewhere inside it: se\"> I'm trying to find the beginning of it using: str.IndexOf("se\\\">") which returns -1 Why isn't it finding the substring? Note: due to editing the snippet showed 5x \ for a while, the original had 3 in a row. ...

PHP - Function to skip strtolower() if variable contain "wikipedia.org"

Hello, My site allows users to enter URLs into a database. I am using the code "$site = strtolower($site);" to make all of these URLs lower-case. However, I just realized that Wikipedia URLs are case sensitive, so I would like to avoid using "$site = strtolower($site);" on Wikipedia URLs, all of which contain "wikipedia.org". How co...

Replace \\ with \ in java

I have to replace '\\' with '\' in Java. The code i am using is System.out.println( (MyConstants.LOCATION_PATH + File.separator + myObject.getStLocation() ).replaceAll("\\\\", "\\") ); But i don't know why it is throwing 'StringIndexOutOfBoundsException'. It says 'String index out of range: 1' What could be the reason? I guess it i...

How do I split an address string in T-SQL?

I want to split a column into 4 columns based on column. Eg: column value includes 'City_Name' , 'State' ,Zipcode' ,'Country' I want to split it into 4 different columns like City_Name, State, Zipcode, Country. How can I do this using T-SQL? ...

RegEx to randomly set case of characters in a string

What I'm looking for is a RegEx to mix the character case of a given string for use in functional testing. Example Input: The Quick Brown fox jumps over the Lazy Dog. Sample Expected Output: tHe QUiCk BrOwn FoX jUMPs OvER tHe lAzY dOg. It would be nice if the output was different every time the RegEx were applied. For example, giv...

Append html space algorithm

This question is along the lines of http://stackoverflow.com/questions/371088/html-table-horizontal-spacing We have an old code base and can not use css. When an entire column in a table is empty, the resulting table is very ugly. We have a text email solution that adds spaces to the end up a word up to the remaining set of characters...

Regular expression to find and remove duplicate words

Using regular expressions in C#, is there any way to find and remove duplicate words or symbols in a string containing a variety of words and symbols? Ex. Initial string of words: "I like the environment. The environment is good." Desired string: "I like the environment. is good" Duplicates removed: "the", "environment", "." ...

How to append two strings in Python?

I have done this operation millions of times, just using the + operator! I have no idea why it is not working this time, it is overwriting the first part of the string with the new one! I have a list of strings and just want to concatenate them in one single string! If I run the program from Eclipse it works, from the command-line it do...

How to remove bad words list in VB.NET?

How can I find words like and, or, to, a, no, with, for etc. in a sentence using VB.NET and remove them. Also where can I find all words list like above. Thanks ...

When to use Regex vs Built in String Methods?

I've noticed a lot of little debates about when to use regex and when to use a built in string function like String.Replace() (.NET). It seems a lot of people recommend always, always, always using regex whenever you deal with strings at all (besides just displaying them). Is this really best practice or just a wrong impression on my p...

Escaping the '\' character in the replacement string in a sed expression

I am trying to take a line of text like 13) Check for orphaned Path entries and change it to (I want the bash color codes to colorize the output, not display on the screen) \033[32m*\033[0m Check for orphaned Path entries with bash color codes to colorize the asterisk to make it stand out more. I have a sed command that does m...

Functions to manipulate IPv4 addresses in C#?

Given a IPv4 address in the form of a string (ex. "10.171.24.69") and a netmask (ex. "255.255.255.128" or "25" for number of bits in network part) I need to compute the broadcast address, which may be by either zeroing or one-ing the bits in the host part (depending on the IPUseZeroBroadcast property which I can query via WMI). I'm exam...

How can I convert this javascript function to PHP?

function escCtrlChars(str) { return str.replace(/[\0\t\n\v\f\r\xa0'"!-]/g, function(c) { return '!' + c.charCodeAt(0) + '!'; }); } Ok this is a function that replaces control characters from a string with another string starting and ending with ! My question is. Is c the character found while...

How to get time elapsed in milliseconds

Since performance of string concatenation is quite weak in VB6 I'm testing several StringBuilder implementations. To see how long they're running, I currently use the built-in Timer function which only gives me the number of seconds that have passed after midnight. Is there a way (I guess by importing a system function) to get somet...

System.Text.StringBuilder limit

Hi, I've read that the StringBuilder type has a limit (the default is 16 characters), and when you append some text to it, beyond its limit, a new instance is created with a higher limit and the data is copied to it. I tried that using the following code : StringBuilder test = new StringBuilder("ABCDEFGHIJKLMNOP",16); test.Append("ABC")...

How do I create subset words for an anagram application (php) ?

I created an anagram creating application, by creating an anagram field in my database, with a lower cased alphabetically stored string. For example, suction becomes cinostu, ear becomes aer, and so on. What I want to do now is create sub words from the original anagram searched for. Example: How would you go about pulling the subset ...