string-manipulation

How can I do the multiple replace in python?

As asked and answered in HERE, I need to replace '[' with '[[]', and ']' with '[]]'. I tried to use s.replace(), but as it's not in place change, I ran as follows to get a wrong anwser. path1 = "/Users/smcho/Desktop/bracket/[10,20]" path2 = path1.replace('[','[[]') path3 = path2.replace(']','[]]') pathName = os.path.join(path3, "*.txt...

Pros and Cons of programming languages for XML & string manipulation

I don't mean this to be opinionated. What are serious pros/cons of various server-side languages in regards to creating/modifying xml. I'm currently researching new platform/language direction and we deal with a lot of xml. We also do a lot of string manipulation, what advantages/disadvantages do different languages have in regards to...

Replace More Than 1 Instance with PHP

Say I have sometext-somemore--test---test2 how could I have it replace all instaces where there are more than 1 - and have it replace them with just 1 so it would look like this sometext-somemore-test-test2 ...

C - check if string is a substring of another string

I need to write a program that takes two strings as arguments and check if the second one is a substring of the first one. I need to do it without using any special library functions. I created this implementation, but I think it's always returning true as long as there is one letter that's the same in both strings. Can you help me out h...

Python string manipulation

I'm trying to split a string into a int list for further processing. But somehow I can't remove certain whitespaces in between elements of the list. The string x is supposed to have a length of 1000 instead of 1019. I tried reading the documentation for python and saw the function strip() for stripping whitespaces from strings. However, ...

How to handle HTML Strings in Cocoa Touch

I'm using a RSS Reader and works fine when I tap the UITableViewCell to load the <link> either in a UIWebView or to open Safari on that link. But I really want to learn how to load the Topic content into the application instead showing the entire site or jump to Safari In the RSS feed per each <item> there is a <body> tag (and a <Descr...

How do I concatenate 2 strings in NSIS

How do I concatenate 2 strings in NSIS? ...

Classic string manipulation interview questions?

Hi, I am scheduled to have an onsite interview so I am preparing few basic questions. According to the company profile, they are big on string manipulation questions. So far I have manually coded these functions: String length, copy, concat, remove white space Reverse Anagrams Palindrome Please can some can give me a list of more cla...

Modify strings in Rails?

Hey everyone, So I'm new to Rails (teaching myself as a senior project in high school), and I'm trying to figure out how to modify these strings. Let's say someone writes the following string in a form: "you know you are a geek when" How can I automatically change it to this: "You know you are a geek when..."? I need Rails to check t...

Finding ALL positions of a substring in a large string in C#

Alright, so what i have, is a large string i need to parse, and what i need to happen, is find all the instances of extract"(me,i-have lots. of]punctuation, and store them to a list. So say this piece of string was in the beginning and middle of the larger string, both of them would be found, and their index's would be added to the Lis...

How to lowercase every element of a collection efficiently?

Whats the most efficient way to lower case every element of a list or set? My idea for a List: final List<String> strings = new ArrayList<String>(); strings.add("HELLO"); strings.add("WORLD"); for(int i=0,l=strings.size();i<l;++i) { strings.add(strings.remove(0).toLowerCase()); } is there a better, faster way? How would this exmap...

What is the REGEXP php syntax to change LastName, Firstname to FirstName LastName?

I would like to change the order of names from Last, First to First Last. I don't know the REGEXP and the php syntax for it. ...

Capitalize only first character of string and leave others alone? (Rails)

Hi, I'm trying to get Rails to capitalize the first character of a string, and leave all the others the way they are. I'm running into a problem where "i'm from New York" gets turned into "I'm from new york." What method would I use to select the first character? Thanks EDIT: I tried to implement what macek suggested, but I'm getti...

How do I apply a string function to an array?

I was fortunate enough to receive this code (flips Lastname, Firstname) from an earlier post. $name = "Lastname, Firstname"; $names = explode(", ", $name); $name = $names[1] . " " . $names[0]; How do I apply the function to each value in an array that is in the form: $ginfo ->$(LastName, FirstName). I tried the code below, but it do...

comparing actual IP with partial IP in PHP

Using PHP I'd like to compare an actual ip address to part of one, and see if it matches. For example I want to see if the address matches 12.34.. <?php $rem_address = getenv('REMOTE_ADDR'); $temp = substr ($rem_address,0,6) if ($temp == "12.34.") echo "It's a match"; ?> Is there an easier/better way to do this? ...

What's the easiest way to assign a string returned from the server to a javascript string?

The following does not work: var js_str= '<?php echo $str_from_server; ?>'; The problem is that, $str_from_server can contain any characters. If it contains single quotes or line breaks or others, the above code will break. And I do not have access to the server-side code. What's the easiest way to "escape" the contents of $str_from_s...

what's the C# equivalent of string$ from basic

And is there an elegant linqy way to do it? What I want to do is create string of given length with made of up multiples of another string up to that length So for length - 9 and input string "xxx" I get "xxxxxxxxx" (ie length 9) for a non integral multiple then I'd like to truncate the line. I can do this using loops and a StringBu...

How do I apply a string function to a table column?

As part of a query result, a column with names is returned. I want to apply a function so that the order of first and last name is flipped in my $db results. What is the most efficient way to accomplish this? There answer probably lies in using either the foreach function, array_walk or array_map but I don't know the proper syntax. ...

formatting an array of mobile numbers

Hi, I am creating a SMS app the following code is supposed to: check if the mobile/cell number is 11 characters long. check if the number starts with 07. If neither of these conditions are met, it should remove the number from the array. So the following numbers would be valid: 07123456789,07123456790,07123456791,07123456792,07123...

What's a good way of building up a String given specific start and end locations?

(java 1.5) I have a need to build up a String, in pieces. I'm given a set of (sub)strings, each with a start and end point of where they belong in the final string. Was wondering if there were some canonical way of doing this. This isn't homework, and I can use any licensable OSS, such as jakarta commons-lang StringUtils etc. My com...