string

JS Regex For Human Names

I'm looking for a good JavaScript RegEx to convert names to proper cases. For example: John SMITH = John Smith Mary O'SMITH = Mary O'Smith E.t MCHYPHEN-SMITH = E.T McHyphen-Smith John Middlename SMITH = John Middlename SMITH Well you get the idea. Anyone come up with a comprehensive solution? ...

How to get the function name as string in Python?

In Python, How do I get the function name as a string without calling the function? def my_function(): . . . print get_function_name_as_string(my_function) # my_function is not in quotes output => "my_function" is this available in python? if not, any idea how to write get_function_name_as_string in python? ...

How does PHP do recursive function calls?

PHP (among others) will execute the deepest function first, working its way out. For example, $text = strtoupper(str_replace('_', ' ', file_get_contents('file.txt'))); I'm doing something very similar to the above example for a template parser. It looks for the tags {@tag_name} and replaces it with a variable of the name $tag_name....

Pattern matching and placeholder values

Language: C# Hello, I'm writing an application that uses renaming rules to rename a list of files based on information given by the user. The files may be inconsistently named to begin with, or the filenames may be consistent. The user selects a list of files, and inputs information about the files (for MP3s, they would be Artist, Tit...

Java -> Apache Commons StringEscapeUtils -> escapeJavaScript

For a very simple ajax name lookup, I'm sending an id from the client webpage to the server (Tomcat 5.5, Java 5), looking it up in a database and returning a string, which is assigned to a javascript variable back in the client (and then displayed). The javascript code that receives the value is pretty standard: //client code - javascr...

How do I perform string operations on variables in a for loop?

This sounds dumb, but I can't get it to work. I think i just dont' understand the difference between %%v, %v% and %v Here's what I'm trying to do: for %%v in (*.flv) do ffmpeg.exe -i "%%v" -y -f mjpeg -ss 0.001 -vframes 1 -an "%%v.jpg" This successfully generates a thumbnail for each of the movies, but the problem is: movie.flv -> m...

In C#: Add Quotes around string in a comma delimited list of strings

This probably has a simple answer, but I must not have had enough coffee to figure it out on my own: If I had a comma delimited string such as: string list = "Fred,Sam,Mike,Sarah"; How would get each element and add quotes around it and stick it back in a string like this: string newList = "'Fred','Sam','Mike','Sarah'"; I'm assumi...

In Java, for a string x, what is the runtime cost of s.length()? Is it O(1) or O(n)?

I've been told that code such as: for (int i=0; i<x.length(); i++) { // blah } is actually O(n^2) because of the repeated calls to x.length(). Instead I should use: int l=x.length(); for (int i=0; i<l; i++) { // blah } Is this true? Is string length stored as a private integer attribute of the String class? Or does lengt...

What defines data that can be stored in strings

Hi, A few days ago, I asked why its not possible to store binary data, such as a jpg file into a string variable. Most of the answers I got said that string is used for textual information such as what I'm writing now. What is considered textual data though? Bytes of a certain nature represent a jpg file and those bytes could be repre...

How do I get a particular word from a string in PHP?

Say you have a string, but you don't know what it contains. And you want to replace all occurences of a particular word or part of a word with a formatted version of the same word. For example, I have a string that contains "lorem ipsum" and i want to replace the entire word that contains "lo" with "lorem can" so that the end result woul...

Quick & Dirty way to update "IDs" in a string formatted as XML (C#)

For a one-shot operation, i need to parse the contents of an XML string and change the numbers of the "ID" field. However, i can not risk changing anything else of the string, eg. whitespace, line feeds, etc. MUST remain as they are! Since i have made the experience that XmlReader tends to mess whitespace up and may even reformat your ...

How to use wide string literals in c++ without putting L in front of each one

You'll have to forgive my ignorance, but I'm not used to using wide character sets in c++, but is there a way that I can use wide string literals in c++ without putting an L in front of each literal? If so, how? ...

what's the quickest way to extract a 5 digit number from a string in c#

what's the quickest way to extract a 5 digit number from a string in c#. I've got string.Join(null, System.Text.RegularExpressions.Regex.Split(expression, "[^\\d]")); Any others? ...

In C#, should I use string.Empty or String.Empty or "" ?

In C#, I want to initialize a string value with an empty string? How should I do this? What is the right way, and why? string willi = string.Empty; or string willi = String.Empty; or string willi = ""; or ? UPDATE Thank you very much for your answers. It seems, that even the easiest questions can start quite interesting dis...

Evaluating expressions inside C++ strings: "Hi ${user} from ${host}"

I'm looking for a clean C++ way to parse a string containing expressions wrapped in ${} and build a result string from the programmatically evaluated expressions. Example: "Hi ${user} from ${host}" will be evaluated to "Hi foo from bar" if I implement the program to let "user" evaluate to "foo", etc. The current approach I'm thinking ...

Convert MYSQL_ROW type to String

I am using the MYSQL C API and I have a MYSQL_ROW object that I would like to convert to a string. Does anyone know how to do this? I haven't found anything in the API's doc yet. string str = (string)row[0] <-- runtime error P.S. I tried casting it to a string but it doesn't work ...

PHP removing a character in a string

Hello, My php is weak and I'm trying to change this string: http://www.site.com/backend.php?/c=crud&amp;m=index&amp;t=care to be: http://www.site.com/backend.php?c=crud&amp;m=index&amp;t=care removing the / after the ? on backend.php. Any ideas on the best way to do this? Thanks! ...

What should these comparisons return?

I've got an application that's using string.compare(string,string) to sort some values. The thing I can't figure out is why "1022" compares as less than "10-23" and "10-23" compares as less than "1024". Is there something specific to the value of "-" that causes this result? Will that overload of string.compare give the same result wi...

Tokenizing strings in c

I have been trying to tokenize a string using SPACE as delimiter but it doesn't work. Does any one have suggestion on why it doesn't work? Edit: tokenizing using: strtok(string, " "); the code is like the following pch = strtok (str," "); while (pch != NULL) { printf ("%s\n",pch); pch = strtok (NULL, " "); } ...

Coldfusion adding extra quotes when constructing database queries in strings

I am coding in ColdFusion, but trying to stay in cfscript, so I have a function that allows me to pass in a query to run it with <cfquery blah > #query# </cfquery> Somehow though, when i construct my queries with sql = "SELECT * FROM a WHERE b='#c#'" and pass it in, coldfusion has replaced the single quotes with 2 single quotes. ...