string-manipulation

efficiency in textbox control access vs working on local copy of text.

I was programming a small notepad like app with some extra functionalities. I am using a rich textbox as the main area. My question is while performing operations on the contents of the textbox, like code formatting, highlighting, etc which might require reading each character and replacing wherever necessary. Moving back across text in...

[Javascript] How to replace strings from an array

I'm working on a piece of code that uses regex expressions to do a find/replace for emoticons in a chat. However, I want to use the same array of values and output them as a reference. The regex works fine for my searches, but when I tried to do a replace on the regex search string before I output it for my help, I still end up with a s...

Dealing with '/'es in links

I am reading in a number of strings which have /'es through them, the most common example being dates/numbers like 05/06, 07/08, etc. I am using ASP.NET MVC2 and generating links off of these strings read out of DB, which therein lies the problem. Obviously a link to: www.mysite.com/yearperiod/05/06/detail will not work the same as a...

Regular expression how to search for () and replace with[]

Silly question, but I do not know how to find (2000) into a regular expression and replace it with [2000] ...

How to split a string on numbers and it substrings?

How to split a string on numbers and substrings? Input: 34AG34A Expected output: {"34","AG","34","A"} I have tried with Regex.Split() function, but I can not figure out what pattern would work. Any ideas? ...

Java String declaration

What is the difference between String str = new String("SOME") and String str="SOME" Does these declarations gives performance variation. ...

Modifying strings in C

I need to store the following strings in 3 char * variables in C: [foo] [foo]:[bar] [foo]:[bar]:[tat] Each individual string such as "foo" is received at one point of time via a char* pointer, the corresponding output string is produced immediately before receiving the second string, and the total number of individual strings is known...

How can I do a case Insensitive String.Replace in c#?

Possible Duplicate: Is there an alternative to string.Replace that is case-insensitive? I need to find and replace a string and ignore the case in c#. What is the best way I can accomplish this? Regex? ...

Can you pull apart a string?

I'm storing a string in a database with a value such as "020734". I would like to be able to pull the string apart. I have: String values = "020734"; I need: String values = "020734"; String value1 = "02"; String value2 = "07"; String value3 = "34"; Could you guys possibly point me in a general direction? ...

How to delete part of a CSV string using Ruby?

Hi, I have a string: "116,118,120,130" and will want to delete either the first, last or any value in between upon execution. To to this I was using: "116,118,120,130".gsub('118','') but the problem is the string contains an extra unnessesary comma: "116,,120,130" and if I use "116,118,120,130".gsub(',116','') it will remo...

Python 3 I think I have a type mismatch but can't find it

Hi, I'm using Python 3.1 to write a simple game involving naming state capitols. I think I have some kind of type mismatch but I don't know what it is. I think it's when I compare the player's answer to the real answer, but don't know how to make it right. from random import * states = {} print ("Guess State Capitols") statefile = o...

How to shave off last character using sed?

That is, going from ABCD -> ABC ...

How to build Acronyms of a phrase in PHP

Hi I'm looking for a way that I can extract the first letter of each word from an input field and place it into a variable. Example: if the input field is "Stack-Overflow Questions Tags Users" then the output for the variable should be something like "SOQTU" Any help is appreciated. Thanks ...

Easier way to create alphanumeric + '_' string from existing string?

Is there a better/easier way to create a \w+ string from an existing string? char *FixName(char *name) { char *ptr, tmp; char *new = malloc(strlen(name)+1); sprintf(new, "str_"); for (ptr = name + 4; *ptr; ptr++) { if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'Z') || ...

MySQL: How can I remove trailing HTML from a field in the database ?

I want to remove some rogue HTML from a DB field that is supposed to contain a simple filename. Example of ok field: myfile.pdf Example of not ok field: myfile2.pdf<input type="hidden" id="gwProxy" />... Does anyone know a query I can run that can remove the HTML part but leave the filename? i.e. remove everything from the first < ...

Parsing 'time string' with Python?

I'm writing an application that involves having users enter time's in the following format: 1m30s # 1 Minute, 30 Seconds 3m15s # 3 Minutes, 15 Seconds 2m25s # 2 Minutes, 25 Seconds 2m # 2 Minutes 55s # 55 Seconds The data can have a single "minute designation", a single "second designation", or both. What is the proper way ...

Elegant way to split string into 2 strings on word boundaries to minimize length difference

I have a working solution right now, but it seems really ugly for something so (seemingly) simple. I tried just breaking it when adding a word goes over the halfway mark, both splitting before and after adding the word, but depending on the length of the words it's either imbalanced towards the first or second line. Sample inputs t...

string ToUpper() function with ToString()

Hi, I have used a string in C# where i am using C# in Visual studio 2008. I wanted to convert it to uppercase. string lowerString = txtCheck.Text; string upperString = lowerString.ToUpper(); Normally this is how i should have used, But the thing is i didn't get any error when i used it like this string upperString = lowerString.ToUp...

Split string of varying length using regex

I don't know if this is possible using regex. I'm just asking in case someone knows the answer. I have a string ="hellohowareyou??". I need to split it like this [h, el, loh, owar, eyou?, ?]. The splitting is done such that the first string will have length 1, second length 2 and so on. The last string will have the remaining charact...

Given a list of words, make a subset of phrases with them

What is the best way performance wise to take a list of words and turn them into phrases in python. words = ["hey","there","stack","overflow"] print magicFunction(words) >>> ["hey","there","stack","overflow", "hey there stack","hey there", "there stack overflow","there stack", "stack overflow", "hey there stack overflow" ] Order does...