string-manipulation

Strangeness using /usr/xpg4/bin/tr and /usr/bin/tr on Solaris 9

Hi all, I have a file looking like this, "xxxxxx" "yyyyyy" "aaaaaa" "cccccc" "bbbbbb" "eeeeee" "oooooo" "zzzzzz" Wanting to replace each \n in this file I use: tr '\n' ',' < INPUT > OUTPUT Which works fine. The output is to be expected: "xxxxxx","yyyyyy","aaaaaa","cccccc".... However I can't do any manipulation using sed or aw...

How can I split a string into two separate arrays using the .NET framework?

I've got a string containing both ints and a string. How do I split it into two arrays, one for ints and one for the string? I also need to maintain the order because I'm writing a file parsing system that depends on reading in and correctly splitting these strings. EDIT: Here's a sample input, and what I would like as output: ~Wolf 10...

Why are most string manipulations in Java based on regexp?

In Java there are a bunch of methods that all have to do with manipulating Strings. The simplest example is the String.split("something") method. Now the actual definition of many of those methods is that they all take a regular expression as their input parameter(s). Which makes then all very powerful building blocks. Now there are tw...

How to remove numbers from a string with RegEx

I have a string like this: " 23 PM" I would like to remove 23 so I'm left with PM or (with space truncated) just PM. Any suggestions? Needs to be in PHP ...

Strip document root from full server path in PHP

OK, I have defined a PHP constant that points to a file on the server like this: define('SOME_FILE', str_replace('//', '/', str_replace('\\', '/', dirname(__FILE__) . '/foo-bar.txt'))); SOME_FILE will contain a full path + filename which is useble in PHP functions like include, fopen, etc. Now if I want to use this path as an URL in m...

I need a case-insensitive Replace method that works with the StringBuilder class

I need a case-insensitive Replace method for the StringBuilder class. The code should work with the existing StringBuilder. An extension method implementation would be nice. Following is how I plan to use the method: [TestMethod] public void StringBuilder_Replace_TTD() { StringBuilder oRequestText = new StringBuilder(...

How to replace a non-static substring case-insensitively

This question is similar to this except that the substring to be replaced is only known at the runtime. I want to write the definition of ireplace, that behaves like this: >>> ireplace(r'c:\Python26\lib\site.py', r'C:\python26', r'image\python26') r'image\python26\lib\site.py' >>> ...

split a file name

Hello How do i write a python script to split a file name eg LN0001_07272010_3.dat and to rename the file to LN0001_JY_07272010? also how do i place a '|' and the end of each line in this file(contents) each line is a record? ...

SQL how to cut off string

I have column of strings with a ctiy state and number in each. SPOKANE, WA 232/107 LAS VEGAS, NV 232/117 PORTLAND, OR 232/128 Theres many more than just that but I am wondering how either I could cut off the numbers in this column and jsut show the city and state or even better cut off the numbers and make c...

Parse Tokens from a String - C Programming - StrTok Issue

My application produces strings like the one below. I need to parse values between the separator into individual values. 2342|2sd45|dswer|2342||5523|||3654|Pswt I am using strtok to do this in a loop. For the fifth token, I am getting 5523. However, I need to account for the empty value between the two separators || as well. 5523 ...

Stripping some characters out of a string

I try to remove some non-safe characters from a string but i believe i have a problem on my RegExp object. What i try to do below is if there are chars whose encoded length is greater than 3 chars they should be replaced with a space. So if encoded value is %3D which is = sign, it is ok to have in my string. But if it is an ’ apostroph...

Question about reversing a string

i am trying to do a simple string manipulation. input is "murder", i want to get "murderredrum". i tried this String str = "murder"; StringBuffer buf = new StringBuffer(str); // buf is now "murder", so i append the reverse which is "redrum" buf.append(buf.reverse()); System.out.println(buf); but now i get "redrumredrum" instead of "m...

Puzzle: Splitting An HTML String Correctly

I'm trying to split an HTML string by a token in order to create a blog preview without displaying the full post. It's a little harder than I first thought. Here are the problems: A user will be creating the HTML through a WYSIWYG editor (CKEditor). The markup isn't guaranteed to be pretty or consistent. The token, read_more(), can be ...

PHP get the letter

Variable $name (string) gives something like (possible values): "Elton John" "2012" " George Bush" " Julia" "Marry III Great" Want to catch the first letter of $name and add it to $letter variable. It's important how many words (divided with spaces " ") the string has: If there is just one word, set $letter to the first letter of t...

Splitting a string intelligently in VB.net

I want to break a string into chunks of 200 characters or smaller, but breaking at the spaces. How can I do this in VB.net? For example: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ut dui et sapien ultricies laoreet. Duis eleifend ante et tortor adipiscing tincidunt. Nulla sagittis purus sit amet mauris convallis auc...

Parse Date from String in this format : dd/MM/yyyy [to dd/MM/yyyy]

Hi guys, I thinking what is the best way in Java to parse the String with this format dd/MM/yyyy [to dd/MM/yyyy]. The string with the [] are optional and dd stand for the 2 digit presentation of dates, MM is the 2 digit presentation of month and yyyy is the 4 digit presentation of year. Update Thanks guys for the fast response, howe...

Fastest way of deleting a value in a comma separated list

I've got a list of names separated by commas (they may contain other characters), or be empty, but generally looking like this: NameA,NameB,NameC I need to create a function to delete a name if its present in the list and which restores the comma separated structure. eg: if NameA is to be deleted, I should end up with: NameB,NameC ...

PHP - How to replace a phrase with another?

How can i replace this <p><span class="headline"> with this <p class="headline"><span> easiest with PHP. $data = file_get_contents("http://www.ihr-apotheker.de/cs1.html"); $clean1 = strstr($data, '<p>'); $str = preg_replace('#(<a.*>).*?(</a>)#', '$1$2', $clean1); $ausgabe = strip_tags($str, '<p>'); echo $ausgabe; Before I alter the ...

Best way get first word and rest of the words in a string in C#.

In C# var parameters = from line in parameterTextBox.Lines select new {name = line.Split(' ').First(), value = line.Split(' ').Skip(1)}; Is there a way to do this without having to split twice? ...

Extracting tokens where some are optional

I need to parse out time tokens from a string where the tokens are optional. Samples given: tt-5d10h tt-5d10h30m tt-5d30m tt-10h30m tt-5d tt-10h tt-30m How can I, in Python, parse this out preferably as the set (days, hours, minutes)? ...