string

Using double, return string

In the application I'm writing, one of the methods allows for the numbers the user entered to be turned into letters. For example, the user will be entering grades (as doubles) and the program will decide (when the criteria is met) to return the letter associated with the number. Initially, I had it written like this: public void GetGra...

long <-> str binary conversion

Is there any lib that convert very long numbers to string just copying the data? These one-liners are too slow: def xlong(s): return sum([ord(c) << e*8 for e,c in enumerate(s)]) def xstr(x): return chr(x&255) + xstr(x >> 8) if x else '' print xlong('abcd'*1024) % 666 print xstr(13**666) ...

There is a function to use pattern matching (using regular expressions) in C++?

There is a simple C++ method to use pattern matching on strings? The code should sound like this: if (regexpcmp("l?nole*[0-9]", "linoleum1")) { //we have a match! } else { //no match } ...

Php function to determine if a string consist of only alphanumerical characters?

Is there a Php function to determine if a string consist of only ASCII alphanumerical characters? Note: I'm sorry if the question sounds dumb to some, but I couldn't easily find such a function in the Php manual. ...

RBuf8 to char* in Symbian C++

Hi, I am downloading a text string from a web service into an RBuf8 using this kind of code (it works..) void CMyApp::BodyReceivedL( const TDesC8& data ) { int newLength = iTextBuffer.Length() + data.Length(); if (iTextBuffer.MaxLength() < newLength) { iTextBuffer.ReAllocL(newLength); } iTextBuffer....

How does Perl decide to treat a scalar as a string or a number?

Consider the following code and its output: Code #!/usr/bin/perl -w use strict; use Data::Dumper; my $HOURS_PER_DAY = 24.0 * 1.0; my $BSA = 1.7 * 1.0; my $MCG_PER_MG = 1000.0 * 1.0; my $HOURS_DURATION = 20.0 * $HOURS_PER_DAY; my $dummy = $HOURS_PER_DAY * $BSA * $MCG_PER_MG * $HOURS_DURATION; print Dumper($HOURS_PER_DAY); print Dumpe...

'Proper' collection to use to obtain items in O(1) time in C# .NET?

Something I do often if I'm storing a bunch of string values and I want to be able to find them in O(1) time later is: foreach (String value in someStringCollection) { someDictionary.Add(value, String.Empty); } This way, I can comfortably perform constant-time lookups on these string values later on, such as: if (someDictionary.c...

How do I convert a double into a string in C++?

I need to store a double as a string. I know I can use printf if I wanted to display it, but I just want to store it in a string variable so that I can store it in a map later. ...

Is there a way of making strings file-path safe in c#?

My program will take arbitrary strings from the internet and use them for file names. Is there a simple way to remove the bad characters from these strings or do I need to write a custom function for this? ...

c# evaluating string "3*(4+2)" yield int 18

Is there a function the the .Net framework that can evaluate a numering expression contained in a string and return the numeric result? IE: string mystring = "3*(2+4)"; int result = EvaluateExpression(mystring); Console.Writeln(result); prints 18. Is there a standard framework function that you can replace my EvaluateExpression with...

Java Strings: "String s = new String("silly");"

I'm a C++ guy learning Java. I'm reading Effective Java and something confused me. It says never to write code like this: String s = new String("silly"); Because it creates unnecessary String objects. But instead it should be written like this: String s = "No longer silly"; Ok fine so far...However, given this class: public final ...

PHP $string{0} vs. $string[0];

In PHP you can access characters of strings in a few different ways, one of which is substr(). You can also access the Nth character in a string with curly or square braces, like so: $string = 'hello'; echo $string{0}; // h echo $string[0]; // h My question is, is there a benefit of one over the other? What's the difference between ...

How can I find the Largest Common Substring between two strings in PHP?

Is there a fast algorithm for finding the Largest Common Substring in two strings or is it an NPComplete problem? In PHP, I can find a needle in a haystack: <?php if (strstr("there is a needle in a haystack", "needle")) { echo "found<br>\n"; } ?> I guess I could do this in a loop over one of the strings but that would be very ex...

Switch Statement With Strings in Java?

Simple question -- why can't I switch on a String in Java, and as far as anyone knows, is this functionality going to be put into a later Java version? EDIT: If someone can point me to an article, or themselves explain why I can't do this, as in, the technical way Java's switch statement works, it would be most appreciated. UPDATE: Alo...

C++ string that can be NULL

I'm used to passing around string like this in my C++ applications: void foo(const std::string& input) { std::cout << input.size() << std::endl; } void bar() { foo("stackoverflow"); } Now I have a case where I want the string to be NULL: void baz() { foo("stackoverflow"); foo(NULL); // very bad with foo implementation above ...

How to increment a java String through all the possibilities?

I need to increment a String in java from "aaaaaaaa" to "aaaaaab" to "aaaaaac" up through the alphabet, then eventually to "aaaaaaba" to "aaaaaabb" etc. etc. Is there a trick for this? ...

Java String Parameters

I'm coming from a .net background and want to know the accepted way of creating a method that returns a boolean and modifies a string that was passed in via parameter. I understand Strings are immutable in Java so the below snippet will always produce an empty string. I am constrained to return boolean only. Exceptions can't be thrown. I...

Can I access the string returned from a Delphi CreateProcess command?

I'm using the Win32 CreateProcess function to perform a call to an external executable. The executable returns a string. Is there a way I can capture and interrogate the returned string after calling the executable? Failing that, I might have to write out the string to a file in the executable and read that in the calling program afte...

Filtering an Objects Properties by Name

I am doing some simple sanity validation on various types. The current test I'm working on is checking to make sure their properties are populated. In this case, populated is defined as not null, having a length greater than zero (if a string), or not equal to 0 (if an integer). The "tricky" part of this test is that some properties are...

Why doesn't VS 2008 display extension methods in Intellisense for String class

Since String implements IEnumerable<char>, I was expecting to see the Enumerable extension methods in Intellisense, for example, when typing the period in String s = "asdf"; s. I was expecting to see .Select<char>(...), .ToList<char>(), etc. I was then suprised to see that the extension methods do in fact work on the string class, the...