string-manipulation

Regular Expression to find string in Expect buffer

I'm trying to find a regex that works to match a string of escape characters (an Expect response, see this question) and a six digit number (with alpha-numeric first character). Here's the whole string I need to identify: \r\n\u001b[1;14HX76196 Ultimately I need to extract the string: X76196 Here's what I have already: interact...

How to get the difference between two list based on substrings withing each string in the seperate lists.

I have two long list, one from a log file that contains lines formatted like 201001050843 blah blah blah <[email protected]> blah blah and a second file in csv format. I need to generate a list of all the entries in file2 that do not contain a email address in the log file, while maintaining the csv format. Example Log file contains: 2...

Dynamic memory allocation + truncating a string issue

Hi. First post here. I've been fooling around with malloc, realloc and free in order to write some basic functions to operate on C strings (char*). I've encountered this weird issue when erasing the last character from a string. I wrote a function with such a prototype: int string_erase_end (char ** dst, size_t size); It's supposed to...

Python: How do you format a string % number with str.format()

How can I format a string like this "%01.2f" % pr"%01.2f" % some_number but using the str.format() style? I'm used to this: '{0} {1}'.format(somevalue1, somevalue2) Is there a way to use that function style vs the old % style, and still achieve this decimal formatting? ...

How does this formatting code work?

I always have to know why, rather than just how, so here I go: How does this work: '{0:01.2f}'.format(5.555) #returns '5.55' '{0:01.1f}'.format(5.555) #returns '5.5' '{0:1.2f}'.format(5.555) #returns '5.55' again '{0:1.1f}'.format(5.555) #returns '5.5' again Why does this not add zero padding by returning '05.5' instead of j...

What's the difference between quantize() and str.format()?

I don't mean what's the technical difference, but rather, what's the faster/more logical or Pythonic, etc. way to do this: def __quantized_price(self): TWOPLACES = Decimal(10) ** -2 return self.price.quantize(TWOPLACES) or def __formatted_price(self): TWOPLACES = Decimal(10) ** -2 return '{0:.2...

Replace newlines with <p> paragraph and with <br /> tags

So I know how to replace newlines in my C# code. But replacing a newline for a <br /> tag isn't always very correct. So I was wondering what kind of strategy do others use? The correct way I guess would be to use <p> tags and <br /> tags. Here are some examples of the results I would like to get. If there is no newline I want the te...

JQUERY, Extract only the first paragraph

Given a block of text in a TEXT EDITOR (CKEDITOR), with paragraphs contained in PARAGRAPH tags, how can I do in JQUERY to extract only the first paragraph Example: blah blah blah blah blah blah blah blah 123123blah blah blah blah blah blah b1212lah blah blah blah blaasdasdadsh blah To Just: blah blah blah blah blah Thanks ...

String reference run-time error

I have the following program which is giving run time error: The instruction at "x" referenced memory at "y" The memory could not be written. int main() { char *str1 = "Rain"; char *&str2 = str1; cout << str1 << str2 << endl; *str1 = 'M'; cout << str1 << str2 << endl; *str2 = 'P';//Here the error happens ...

Assign variable to manipulated data from jQuery getJSON results

How to assign a variable to returned JSON data that has been manipulated with .replace() as shown below. Purpose: build the URL for the video thumbnail image from video ID returned by JSON. Question: How to assign a video ID (ex. mVWhWsgHzKM) to a variable so thumbnail URL can be constructed. $.getJSON( 'http://gdata.youtube.com/fe...

How to convert string to array in c# without using split function

is there any way to convert a string like "abcdef“ to string array a char each without using the string.split function? Thanks first ...

mysql join table on itself

I am having problems with this and I'm hoping it's possible. I have a table from wordpress which stores post meta data, so the columns and field data cannot be changed (Easily). The table structure is thus post_id meta_key meta_value the meta key stores a field name and the meta_value, the value for that field. I need to group thes...

format string- compile time checking

Is there any way to check the format string at compile time ? Example: Console.WriteLine("{0} is a really {1} site", "stackoverflow.com", "cool");//this will run //this will give an exception as only one argument is supplied Console.WriteLine("{0} is a really {1} site", "stackoverflow.com"); Exception:"Index (zero based) must b...

C to PHP, character processing

Hi all. I have some legacy C code (as a macro) that I am not allowed to change in any way, or replace. This code (eventually) outputs out a digest (C) string based on the source string, performing an operation on the hash value for each character in the string. #define DO_HASH(src, dest) { \ unsigned long hash = 1111; // Seed. You ...

"Extend" the "string" table - how to do it? Is it even a good idea?

I am developing a Lua library in which I needed to uppercase the first letter of a given string. Hence I created the following function: local capitalize = function(s) return string.gsub (s, "(%w)([%w]*)", function (first, rest) return string.upper(first) .. rest end, 1 ) end This initially was an "internal" ...

Objective-C: NSMutableString replaceCharactersInRange raising Exception

I expected this code to replace the hate with some love. NSMutableString *teststring=@"I hate programming my iPhone"; NSString *overwriteSource=@"love"; NSRange temprange=NSMakeRange(2, 4); [teststring replaceCharactersInRange:temprange withString:overwriteSource]; NSLog(@"%@",teststring); This terminates due to an uncaught e...

Parsing HTML to get content using C#

I am writing an application that crawls a group of my web pages. Rather than take the entire source code of the page I'd like to take all of the content and store that and be able to store the page as plain text within a database. The content will be used in other applications and not read by users so there's no need for it to be perfect...

Java string split function acting strange

Hi guys, I am noticing strange behaviour when using the split() method in Java. I have a string as follows: 0|1|2|3|4|5|6|7|8|9|10 String currentString[] = br.readLine().split("\\|"); System.out.println("Length:"+currentString.length); for(int i=0;i < currentString.length;i++){ System.out.println(currentString[i]); } This will p...

Best way to create a string containing multiple copies of another string

I want to create a function that will take a string and an integer as parameters and return a string that contains the string parameter repeated the given number of times. For example: std::string MakeDuplicate( const std::string& str, int x ) { ... } Calling MakeDuplicate( "abc", 3 ); would return "abcabcabc". I know I can do t...

C# string replacement question

Quick question. I have a listbox being populated from a directory listing. Each file contains its name and ~#####. I'm trying to read it all into a string and replace the ~#### with nothing. The #### could be digits from length 1-6 and could be anything from 0-9. Here's the code I'm using: string listItem = (listBox1.SelectedItem...