string

Why can't strings be mutable in Java and .NET?

Why is it that they decided to make string immutable in Java and .NET (and some other languages)? Why didn't they make it mutable? ...

Out of String Space in Visual Basic 6

We are getting an error in a VB6 application that sends data back and forth over TCP sockets. We get a runtime error "out of string space". Has anyone seen this or have any thoughts on why this would happen? It seems like we are hitting some VB6 threshhold so any other thoughts would be helpful as well. thks, ak ...

How do I split this string with javascript?

I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using javascript what is the fastest way to parse this into var name = "john smith"; var street= "123 Street"; etc ...

Fastest way to find objects from a collection matched by condition on string member

Suppose I have a collection (be it an array, generic List, or whatever is the fastest solution to this problem) of a certain class, let's call it ClassFoo: class ClassFoo { public string word; public float score; //... etc ... } Assume there's going to be like 50.000 items in the collection, all in memory. Now I want to obtain as f...

How do I escape a string inside javascript inside an onClick handler?

Maybe I'm just thinking about this too hard, but I'm having a problem figuring out what escaping to use on a string in some javascript inside a link's onClick handler. Example: <a href="#" onclick="SelectSurveyItem('<%itemid%>', '<%itemname%>'); return false;">Select</a> The <%itemid%> and <%itemname%> are where template substitution...

Assign variables with a regular expression

I'm looking for a method to assign variables with patterns in regular expressions with C++ .NET something like String^ speed; String^ size; "command SPEED=[speed] SIZE=[size]" Right now I'm using IndexOf() and Substring() but it is quite ugly ...

Simple way to parse a person's name into its component parts?

A lot of contact management programs do this - you type in a name (e.g., "John W. Smith") and it automatically breaks it up internally into: First name: John Middle name: W. Last name: Smith Likewise, it figures out things like "Mrs. Jane W. Smith" and "Dr. John Doe, Jr." correctly as well (assuming you allow for fields like "prefix" a...

Localize Strings in Javascript

I'm currently using .resx files to manage my server side resources for .Net. The application that I am dealing with also allows developers to plugin javascript into various event handlers for client side validation, etc.. What is the best way for me to localize my javascript messages and strings? Ideally, I would like to store the str...

Calling PHP functions within HEREDOC strings

In PHP, the HEREDOC string declarations are really useful for outputting a block of html. You can have it parse in variables just by prefixing them with $, but for more complicated syntax (like $var[2][3]), you have to put your expression inside {} braces. In PHP 5, it is possible to actually make function calls within {} braces inside...

Sort on a string that may contain a number

I need to write a Java Comparator class that compares Strings, however with one twist. If the two strings it is comparing are the same at the beginning and end of the string are the same, and the middle part that differs is an integer, then compare based on the numeric values of those integers. For example, I want the following strings...

C#: Test if string is a guid without throwing exceptions?

i want to try to convert a string to a Guid, but i don't want to rely on catching exceptions ( for performance reasons - exceptions are expensive for usability reasons - the debugger pops up for design reasons - the expected is not exceptional In other words the code: public static Boolean TryStrToGuid(String s, out Guid value) { ...

Best way to randomize a string array in C#

I was just wondering what is the best way to randomize an array of strings in C#. My array contains about 500 strings and I'd like to create a new Array with the same strings but in a random order. Any suggestions? ...

Why use c strings in c++?

Is there any good reason to use C-strings in C++ nowadays? My textbook uses them in examples at some points, and I really feel like it would be easier just to use a std::string. ...

Which loop has better performance? Why?

String s = ""; for(i=0;i<....){ s = some Assignment; } or for(i=0;i<..){ String s = some Assignment; } I don't need to use 's' outside the loop ever again. The first option is perhaps better since a new String is not initialized each time. The second however would result in the scope of the variable being limited to the loo...

JavaScript string concatenation

Hi, On my team, we usually do string concatentation like this: var url = // some dynamically generated URL var sb = new StringBuffer(); sb.append("<a href='").append(url).append("'>click here</a>"); Obviously the following is much more readable: var url = // some dynamically generated URL var sb = "<a href='" + url + "'>click here</...

What is a performant string hashing function that results in a 32 bit integer with low collision rates?

I have lots of unrelated named things that I'd like to do quick searches against. An "aardvark" is always an "aardvark" everywhere, so hashing the string and reusing the integer would work well to speed up comparisons. The entire set of names is unknown (and changes over time). What is a fast string hashing algorithm that will generate s...

I'm looking for a regular expression to remove a given (x)HTML tag from a string

Let's say I have a string holding a mess of text and (x)HTML tags. I want to remove all instances of a given tag (and any attributes of that tag), leaving all other tags and text along. What's the best Regex to get this done? Edited to add: Oh, I appreciate that using a Regex for this particular issue is not the best solution. Howeve...

How can I join a list into a string (caveat)?

Along the lines of my previous question, how can i join a list of strings into a string such that values get quoted cleanly. Something like: ['a', 'one "two" three', 'foo, bar', """both"'"""] into: a, 'one "two" three', "foo, bar", "both\"'" I suspect that the csv module will come into play here, but i'm not sure how to get the out...

How do I truncate a java string to fit in a given number of bytes, once UTF-8 encoded?

How do I truncate a java String so that I know it will fit in a given number of bytes storage once it is UTF-8 encoded? ...

How can I find the first occurrence of a pattern in a string from some starting position?

I have a string of arbitrary length, and starting at position p0, I need to find the first occurrence of one of three 3-letter patterns. Assume the string contain only letters. I need to find the count of triplets starting at position p0 and jumping forward in triplets until the first occurrence of either 'aaa' or 'bbb' or 'ccc'. Is th...