string

Pretty Date Text in Flex / Flash / Java / C#

Is there a free library or class for formatting a date in a pretty way such as "5 minutes ago" or "yesterday"? I'd be satisfied with the same code in another language that I could port to Actionscript (like Java or C#) ...

Angle brackets in php

I want to store angle brackets in a string in PHP because i want to eventually use mail() to send an HTML email out. The following is the code that doesn't seem to work. while(...) { $msg .= "<img src=\"http://.../images/".$media['Path']."\"&gt;&lt;br&gt;"; echo "message: ".$msg."<br>"; } What I want is for $msg to contain a bu...

How can ruby do this task (Case-insensitive string search & replace in Ruby)?

I have some problem with replace string in Ruby. My Original string : What the human does is not like what animal does. I want to replace to: ==What== the human does is not like ==what== animal does. I face the problem of case sensitive when using gsub. (eg. What , what) I want to keep original text. any solution? ...

C++ - string.compare issues when output to text file is different to console output?

I'm trying to find out if two strings I have are the same, for the purpose of unit testing. The first is a predefined string, hard-coded into the program. The second is a read in from a text file with an ifstream using std::getline(), and then taken as a substring. Both values are stored as C++ strings. When I output both of the strings...

Replace the line containing the Regex

Hi, I have an input string containing multiple lines(demarcated by \n). I need to search for a pattern in the lines and if its found, then replace the complete line with empty string. My code looks like this, Pattern p = Pattern.compile("^.*@@.*$"); String regex = "This is the first line \n" + "And this is second ...

pass a string from managed C# to managed C++

hello, what is the preferred method to pass a string between C++ and C#? i have a c++ class where one of the functions takes a char const * const as parameter. how would i call this function in C#? just using a c#-string doesnt seem to work as the function in C# requires a sbyte* C++ class: public ref class MyClass { public: void S...

How to check if String value is Boolean type in Java?

I did a little search on this but couldn't find anything useful. The point being that if String value is either "true" or "false" the return value should be true. In every other value it should be false. I tried these: String value = "false"; System.out.println("test1: " + Boolean.parseBoolean(value)); System.out.println("test2: " + B...

how to Sort out Mysql odbc connection strings stored in registry as plain text

Mysql odbc connection string is stored in the windows registry as plain text. So someone can find it and view my database. How can I sort out this security problem. thanks ...

String formatting expressions (Python)

String formatting expressions: 'This is %d %s example!' % (1, 'nice') String formatting method calls: 'This is {0} {1} example!'.format(1, 'nice') I personally prefer the method calls (second example) for readability but since it is new, there is some chance that one or the other of these may become deprecated over time. Which do y...

How do we create such a regular expression to extract data?

<br>Aggie<br><br>John<br><p>Hello world</p><br>Mary<br><br><b>Peter</b><br> I'd like to create a regexp that safely matches these: <br>Aggie<br> <br>John<br> <br>Mary<br> <br><b>Peter</b><br> This is possible that there are other tags (e.g. <i>,<strike>...etc ) between each pair of <br> and they have to be collected just like the <b...

Why do you prefer char* instead of string, in C++?

I am a C programmer,now trying to write c++ code.I heard string in C++ was better than char* in terms of security, performance, etc,but sometimes it seems that char * is better choice.Someone suggest that programmer should not use char * in C++ becuase we could do all things that char * could do with string, and its securer and faster. ...

C# Compile-Time Concatenation For String Constants

Does C# do any compile-time optimization for constant string concatenation? If so, how must my code by written to take advantage of this? Example: How do these compare at run time? Console.WriteLine("ABC" + "DEF"); const string s1 = "ABC"; Console.WriteLine(s1 + "DEF"); const string s1 = "ABC"; const string s2 = s1 + "DEF"; Console....

How can I construct this string in a nicer fasion?

I have a tool with a configurable delay (Timespan), and I want to set the text of a label depending on the value. Here is my code as it stands: StringBuilder time = new StringBuilder(); if (Settings.Default.WaitPeriod.Hours > 0) { time.AppendFormat("{0} hour(s)", Settings.Default.WaitPeriod.Hours); } if (Se...

Extracting some data items in a string using regular expression

<![Apple]!>some garbage text may be here<![Banana]!>some garbage text may be here<![Orange]!><![Pear]!><![Pineapple]!> In the above string, I would like to have a regex that matches all <![FruitName]!>, between these <![FruitName]!>, there may be some garbage text, my first attempt is like this: <!\[[^\]!>]+\]!> It works, but as you...

Php script problem

I have a little problem with my script. When I try to run it I receive "Parse error: syntax error, unexpected T_STRING" as long as I have ' sign in my code. When I change all ' into " then I have the same error. So I have to change all " into '. How can I solve it? Here is my code: <?php PutEnv(TNS_ADMIN='C:\Programy\OracleDevelo...

Counting the number of common chars in a string and a vector of strings

My problem is how to count but not count the same character twice. Like comparing 'aba' to 'are' should give 1 as result since it has only one char in common. This is where I got so far: public int sameChars (Vector<String> otherStrs){ int result = 0; String original = "aba"; for (int h= 0; h< otherStrs.size(); h++) { ...

Fast algorithm for searching for substrings in a string

I'd like an efficient algorithm (or library) that I can use in Java to search for substrings in a string. What I would like to do is: Given an input string - INSTR: "BCDEFGH" And a set of candidate strings - CAND: "AB", "CDE", "FG", "H", "IJ" Find any CAND strings that match as substrings within INSTR In this example I wo...

jquery - check if string begins with something?

I know that I can do like ^= to see if an id starts with something, and I tried using that for this, but it didn't work... Basically, I'm retrieving the url and I want to set a class for an element for pathnames that start in a certain way... So, var pathname = window.location.pathname; //gives me /sub/1/train/yonks/459087 I want...

string-split in DrScheme

How do I do equivalent of python's str.split in DrScheme? SRFI-13 doesn't seem to have it provided. ...

efficiency of SQL 'LIKE' statement with large number of clauses

I need to extract information from a text field which can contain one of many values. The SQL looks like: SELECT fieldname FROM table WHERE bigtextfield LIKE '%val1%' OR bigtextfield LIKE '%val2%' OR bigtextfield LIKE '%val3%' . . . OR bigtextfield LIKE '%valn%' My question is: how efficient is this when the number o...