string

ASP.NET MVC 2 Data Annotation Validation -- StringLength Minimum not working on client-side

Hi. On one of my models I have a property annotated with: [StringLength(60, ErrorMessage="Title must be between 60 and 10 characters", MinimumLength=10)] When the form posts to the server, if it's under 10 characters, then validation fails as it should do. However, on the client-side, it only checks that it's under 60 characters -- n...

Why doesn't this method work to assign characters, in JavaScript?

Ok, here goes a newbie question: //function removes characters and spaces that are not numeric. // time = "2010/09/20 16:37:32.37" function unformatTime(time) { var temp = "xxxxxxxxxxxxxxxx"; temp[0] = time[0]; temp[1] = time[1]; temp[2] = time[2]; temp[3] = time[3]; temp[4] = time[5]; temp[5] = ...

String trimming causes memory leak?

I'm curious what the proper way to trim a string is to ensure that no memory leak occurs. I guess this may really be a question based on exactly how free() works. I've included the code for my trim() function. See below. int main() { char* testStr1 = strdup("some string"); char* testStr2 = strdup(" some string"); char* ...

Advantages and disadvantages of using strdup on a string literal

I want to be clear about all the advantages/disadvantages of the following code: { char *str1 = strdup("some string"); char *str2 = "some string"; free(str1); } str1: You can modify the contents of the string str2: You don't have to use free() Faster Any other differences? ...

How do I remove trailing white spaces but not white spaces within a string (nor at the beginning)?

I have a string of varying length and is usually followed by white spaces (of varying length based on he string). i.e. - the string is always 20 characters long var data = "DUR IT R4356 " //with 8 trailing or the string could be var data = "11& 444 DTF# 5676 " //with 3 trailing What is the best way to get rid of those tra...

Replace/remove String between two character

I want to remove a string that is between two characters and also the characters itself , lets say for example: i want to replace all the occurrence of the string between "#?" and ";" and remove it with the characters. From this "this #?anystring; is #?anystring2jk; test" To This "this is test" how could i do it in java ? ...

jquery value substitution

Is this a ligitimate way of determining the selected value of an section/option box with and id of "shirt_size_1221"? var user_id = '1221'; x = "#shirt_size_" + user_id ; alert($(x + " option:selected")); ...

How to use if condition inside string in php

Hi, I want to know if there is a way to use something like this: $t1=1; $t2=2; $t3="$t1>$t2"; if($t3) echo "Greater"; else echo "Smaller"; This will evaluate to true as $t3 is a string, but that's wrong!!! So is there a way to include the if condition inside string. I heard that we can use eval for this: http://stackoverflow....

First Word in String with jquery

Hello! I'm trying to figure out function that will help me wrap first word in string into span. But unfortunately no luck. Can anyone help me please? Many Thanks Dom ...

Split string to equal length substrings in Java

How to split the string "Thequickbrownfoxjumps" to substrings of equal size in Java. Eg. "Thequickbrownfoxjumps" of 4 equal size should give the output. ["Theq","uick","brow","nfox","jump","s"] Similar Question: Split string into equal-length substrings in Scala ...

get atof to continue converting a string to a number after the first non valid ch in a string

hi guys, i'd like to know if there a way to get atof continue converting to number even if there are non valid charcters in the way for example let say i have string "444-3-3-33" i want to covert it to a double a=4443333 (and keep the string as it was) happy to get any suggestions or an alternative way thanks! ...

PosqtgreSQL string comparison

I try to compare strings in PostgreSQL. Here are queries that I execute: select 'UK (z'>'Ukraine'; This one returns true; Then I try following one: select 'UK ('>'Ukraine'; This one returns false; I think, that both of these should return false , and on another PostgreSQL server it behaves correctly. But main server is producing...

Remove new lines from string

$string = " put returns between paragraphs for linebreak add 2 spaces at end "; Want to remove all new lines from string. I've this regex, it can catch all of them, the problem is I don't know with which function should I use it. /\r\n|\r|\n/ $string should become: $string = "put returns between paragraphs for linebreak add 2 sp...

PHP - read variables from a array string field

Hi I have a array that looks like this: $sites = array('Twitter' => 'http://twitter.com/home?status=$status', 'Digg' => 'http://digg.com/submit?phase=2&amp;amp;title=$title', .... ); $status = 'bla bla'; $title = 'asdasf'; foreach($sites as $site_name=>$site_url) echo '<li...

PHP: remove extra space from a string using regex

How do I remove extra spaces at the end of a string using regex (preg_replace)? $string = "some random text with extra spaces at the end "; ...

PHP - replace a string with a variable named like the string

Hi so the string is like this: "bla bla bla {VARIABLE} bla bla" when I use this string somewhere in a function I want to replace {VARIABLE} with $variable (or any other uppercase strings with wrapped within {} charcters). $variable (and any other variables) will be defined inside that function Can i do this? ...

null terminator gives trouble with string length when comparing

I'm trying to compare 2 strings by "==" operator. when i print the string both are identical. but length of one is bigger by one, i figured it is the null terminator. any way to ignore this when comparing?? Thanks!! City* Adjutancy::FromStringToCity(string cityName) const { for (list<City*>::const_iterator it=m_citiesList.begin();it...

iPhone UIStringDrawing usage

Could someone please explain to me how to draw a string using UIStringDrawing instead of using a label? here is my code but for some reason it compiles and the screen is blank... // // MainViewController.m // DotH // #define WINDOW_FRAME [[UIScreen mainScreen] bounds] #define SCREEN_FRAME [UIScreen mainScreen].applicationFrame #defin...

Return the portion of a string before the first occurrence of a character in php

In PHP, what is the simplest way to return the portion of a string before the first occurrence of a specific character? For example, if I have a string... "The quick brown foxed jumped over the etc etc." ...and I am filtering for a space character (" "), the function would return "The" Thanks! ...

php make function inside a variable.

Im sure I have seen an implementation of this in PHP somewhere and I am positive if it exists its a PHP 5 thing. Any way I was wondering if it was possible to set and run a function from a string and set the returned value to the value of the string. e.g. <?php $hi = function(){ return "Hello World"; }; echo $hi(); ?> It probably is ...