string

The difference between + and & for joining strings in VB.Net

Can someone explain the difference? ...

How would you go about designing a function for a perfect hash?

The domain of interest is string matching. Assume I have a structure like this. typedef struct { char *name, int (*function)(); } StringArray StringArray s[] = { {"George", func1}, {"Paul", func2}, {"Ringo", func3}, {"John", func4} } There are a fixed number of strings in the array. They are hard cod...

Hashtable/Dictionary collisions

Using the standard English letters and underscore only, how many characters can be used at a maximum without causing a potential collision in a hashtable/dictionary. So strings like: blur Blur b Blur_The_Shades_Slightly_With_A_Tint_Of_Blue ... ...

Checking if a string can be converted to float in Python

I've got some Python code that runs through a list of strings and converts them to integers or floating point numbers if possible. Doing this for integers is pretty easy if element.isdigit(): newelement=int(element) Floating point numbers are more difficult. Right now I'm using partition('.') to split the string and checking to ...

How can I get a character at a given index in Perl?

If I have a Perl string: $str = "Hello"; how can I get a character at a given index similar to charAt(index)? ...

Good alternative to Eregi() in PHP

I often find myself doing quick checks like this: if (! eregi('.php',$fileName)) $filename.='.php'; But sadly eregi() is going to be deprecated in PHP 6, which means all of my code that uses it will be rendered useless :(. Is there another function that behaves exactly the same way as eregi()? I don't know anything about reg ex...

Java string: how do I get the value of X, Y, and Z from a string "vt X,Y,Z"

how do I get the value of X, Y, and Z from a string "vt X,Y,Z" ...

Win32 LB_GETTEXT returns garbage.

Hello, I have a problem which is most likely a simple problem, but neverthe less still a problem for me. I am using the Listbox in Win32 / C++ and when getting the selected text from my listbox the string returned is just garbage. It is a handle to a struct or similar? Below is the code and an example of what I get. std::string Listbox...

How do I output each Perl array element surrounded in quotes?

I want to output the elements of an array in a specific format in Perl. @myArray = ("A", "B", "C"); $text = something; Something should be the string '"A" "B" "C"' (each element enclosed in double quotes). However, if @myArray is empty, then $text should be too. I thought of using join(), such as $text = "\"" . join("\" \"", @myArra...

How do I replace a token with increasing numbers in Perl?

I want to replace a token in a text file with a number. The token is "<count>" and I want it to be replaced with the number of counts so far. For example: This <count> is a <count> count. The <count> count increases <count><count><count>. <count><count><count><count><count><count> becomes: This 1 is a 2 count. The 3 count increases 4...

How to reverse sed output?

I'm reading from a line that's about 500 characters. How can I get sed to, instead of replacing that string with something, replace the rest of the line with something? In short, I want to remove all the text around a specified string. Deleting columns with awk won't work, because there is an indeterminate amount of characters before and...

How to release the unused capacity of a string

Hi, I am dealing with a lot of strings in my program. These string data don't change through out the whole life time after they being read into my program. But since the C++ string reserves capacity, they waste a lot of space that won't be used for sure. I tried to release those spaces, but it didn't work. The following is the simple c...

(C#) what is the most efficient way to compare two strings?

Just like this page at stakeoverflow.com http://stackoverflow.com/revisions/620144/list I want to compare two strings and found which parts have been modified. ...

How to compare ends of strings in C?

I want to make sure my string ends with ".foo". I am using C, a language I am not totally familiar with. The best way I have found to do it is below. Any C gurus want to make sure I'm doing this elegantly and wisely? int EndsWithFoo(char *str) { if(strlen(str) >= strlen(".foo")) { if(!strcmp(str + strlen(str) - strlen...

[JOGL] Why won't my text show up?

For some reason which I can't figure out for the life of me, my text in my JOGL hello world program won't show up at all. I'll include the display method so you'll all know what I'm talking about. public void display(GLAutoDrawable gLDrawable) { final GL gl = gLDrawable.getGL(); final GLU glu = new GLU(); GLU...

java string to datetime conversion issue

I can't seem to see the problem with the example code below. For some reason seems to be ignoring the year and saying the dates are the same, as can be seen in the output below. I must be missing something simple. 01/28/2006 01/16/2007 Tue Apr 01 00:00:00 PDT 2008 Tue Apr 01 00:00:00 PDT 2008 done import java.util.*; impo...

Simple string encryption in .NET and Javascript

I'm developing an ASP.NET MVC application in which I want to encrypt a short string on the server, using C#, and send it to the client-side. Then on the client-side it will be decrypted through Javascript code. Any thoughts on how to implement this? Do you know of a simple encryption algorithm (doesn't have to be bullet-proof secure) ...

C# comparing similar strings

Hi I have a generic with some filenames (LIST1) and another biggeneric with a full list of names (LIST2). I need to match names from LIST1 to similar ones in LIST2. For example LIST1 - **MAIZE_SLIP_QUANTITY_3_9.1.aif** LIST 2 1- TUTORIAL_FAILURE_CLINCH_4.1.aif 2- **MAIZE_SLIP_QUANTITY_3_5.1.aif** 3- **MAIZE_SLIP_QUANTITY_3_9.2.aif** ...

PHP how to use string as superglobal

Hi, I'm building a small abstract class that's supposed to make certain tasks easier. For example: $var = class::get('id'); would run check if there's pointer id in the $_GET, returning a string or array according to parameters. This should also work for post and request and maby more. I'm doing it in the way there's function for all t...

Is there a CapitalizeFirstLetter method?

Is there a method to do that? Could it be done with an extension method? I want to achieve this: string s = "foo".CapitalizeFirstLetter(); // s is now "Foo" ...