string-manipulation

How to handle string encoding in java ?

I was really discouraged by java's string encoding. There are many auto conversions in it. and I can't found the regular. Anyone have good idea? for example: In a jsp page, it has such link http://localhost:8080/helloworld/hello?world=凹ㄉ And then we need to process it, so we do this: String a = new String(request.getParameter("world"...

Is there a faster way to escape a string?

I have a method that looks like this: public static String escape(String text) { String r = replace(text, "\\", "\\\\"); r = replace(r, "\r", "\\r"); r = replace(r, "\b", "\\b"); r = replace(r, "\t", "\\t"); r = replace(r, "\n", "\\n"); r = replace(r, "\f", "\\f"); return r; } Is there a faster, less brutal way to...

string parsing in C

I'm trying to pass a string to chdir(). But I always seem to have some trailing stuff makes the chdir() fail. #define IN_LEN 128 int main(int argc, char** argv) { int counter; char command[IN_LEN]; char** tokens = (char**) malloc(sizeof(char)*IN_LEN); size_t path_len; char path[IN_LEN]; ... fgets(command,...

C-Strings in C++

I'm learning C++ for one of my CS classes, and for our first project I need to parse some URL's using c-strings (i.e. I can't use the C++ String class). The only way I can think of approaching this is just iterating through (since it's a char[]) and using some switch statements. From someone who is more experienced in C++ - is there a be...

How to insert a string inside another string?

Hi Just looked at function str_pad($input, $pad_length, $pad_str, [STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH]) which helps to pad some string on left, right or on both sides of a given input. Is there any php function which I can use to insert a string inside an input string? for example .. $input = "abcdef"; $pad_str = "@";...

How to extract a string between 2 other strings in python?

Like if I have a string like str1 = "IWantToMasterPython" If I want to extract "Py" from the above string. I write: extractedString = foo("Master","thon") I want to do all this because i am trying to extract lyrics from an html page. The lyrics are written like <div class = "lyricbox"> ....lyrics goes here....</div>. Any suggestions...

How to make next step of a string. C#

The question is complicated but I will explain it in details. The goal is to make a function which will return next "step" of the given string. For example String.Step("a"); // = "b" String.Step("b"); // = "c" String.Step("g"); // = "h" String.Step("z"); // = "A" String.Step("A"); // = "B" String.Step("B"); // = "C" String.Step("G"...

How to modify RegularExpression to Parse vCard/vCalendar to allow a particular field type?

I have an vCard application that needs to read vCard Data, and have found a RegularExpression which gets the FieldName, Encoding and FieldValue from the file, here it is below: ^(?<FIELDNAME>[\w-]{1,})(?:(?:;?)(?:ENCODING=(?<ENC>[^:;]*)|CHARSET=(?<CHARSET>[^:;]*))){0,2}:(?:(?<CONTENT>(?:[^\r\n]*=\r\n){1,}[^\r\n]*)|(?<CONTENT>[^\r\n]*)) ...

How to join NSArray elements into an NSString?

Given an NSArray of NSStrings, is there a quick way to join them together into a single NSString (with a Separator)? ...

Generating HTML (i.e. br and p tags) from plaintext in C++

I've got a bunch of text like this: foo bar baz What's likely to be the most efficient way in C++ of transforming that to this: <p>foo<br />bar</p> <p>baz</p> for large(ish) quantities of text (up to 8000 characters). I'm happy to use boost's regex_replace, but I was wondering if string searching for \n\n might be more efficient?...

How to trim out the space between non letters with PHP?

Say,should keep the space between letters(a-z,case insensitive) and remove the space between non-letters? ...

Strtotime with European date format

Hi, I'm trying to use strtotime to convert the following date: 07/09/2009 17:01:27 It's the Europe/London timezone format for 7th of September The function is inverting the month and the days, is there any workaround? thanks ...

Fastest way to get a random value from a string array in C#?

What's the fastest way to get a random value from a string array in C# on the .net 2.0 framework? I figured they might have had this: string[] fileLines = File.ReadAllLines(filePath); fileLines.GetRandomValue(); Yes, I know GetRandomValue() is not an actual method, is there something similar that's more or less equally short and sweet...

How to center a string in elisp?

I would like to center justify a given input string to a given size so that what is produced is a string with padded spaces either side (left and right) of the input string. The code I have to do this: (defun center-string (string size) (let* ((padding (/ (- size (length string)) 2)) (lpad (+ (length string) padding)) ...

Simple issue with subseq (LISP)

I just started using LISP, coming from a background in C. So far its been fun, although with an incredible learning curve (I'm an emacs newbie too). Anyway, I'm having a silly issue with the following code to parse include statements from c source - if anyone can comment on this and suggest a solution, it would help a lot. (defun inclu...

Patterns for string manipulation (in C# or other languages)

I often find myself writing quite ugly code when doing string manipulations. The code does what's expected, but I would like to feel satisfied with how it looks as well as it performs. Are there any good books, websites, forums that addresses common string manipulation problems? And how would you code the following example scenarios? A ...

Line-breaks in Exception.Message

I'm extending Exception to implement a setter on the Message property. And this works just fine. But somehow this: CustomException.Message = "Test" + Environment.NewLine + "Test Again"; Becomes this: "Test\r\nTest Again" I've also tried this, with no luck: CustomException.Message = @"Test Test Again"; Any ideas? ...

Parsing formatted string.

I am trying to create a generic formatter/parser combination. Example scenario: I have a string for string.Format(), e.g. var format = "{0}-{1}" I have an array of object (string) for the input, e.g. var arr = new[] { "asdf", "qwer" } I am formatting the array using the format string, e.g. var res = string.Format(format, arr) What I...

php - copying some part of string

Hi guys, how can i get some part of string (in symbols). For example: $string = 'one two three'; $numSymbols = 7; %what should I do% $res_string = 'one two'; Help, please. ...

Replace QueryString value using regular expressions

In C#, I'm trying to use regular expressions to replace values in a querystring. So, if I have: http://www.url.com/page.aspx?id=1 I'd like to write a function where I pass in the url, the querystring value and the value to replace. Something along the lines of: string url = "http://www.url.com/page.aspx?id=1"; string newURL = Replac...