string

How to get the end of a C++ string stream?

I'm adding functions to my (simple) log class to make it usable like a stream. Currently, after some modifications, I got this (in my cpp): // blah blah blah... // note: here String is a defined as: typedef std::string String; void Log::logMessage( const String& message ) { logText(); // to be sure we flush the current text if...

What happens when Java Compiler sees many String concatenations in one line?

Suppose I have an expression in Java such as: String s = "abc" + methodReturningAString() + "ghi" + anotherMethodReturningAString() + "omn" + "blablabla"; What's the behaviour of the Java's default JDK compiler? Does it just makes the five concatenations or there is a smart performance trick done? ...

regex not preceeded by a word

I need to find all the strings in a set of c# files, unless they are inside a Contract.Require statement. There could be any amount of text in the string, so between the " and ", and any amount of text between the string and the Contract.Require. I have this: /".+"/ which finds strings, but I need to refine my search. Is this even p...

Mysql bad date (data) in string field how to find/validate?

I have a string field in Mysql (date fields imported from from MSSQL) and I'm using the following to convert the string value and place it in a new (MYSQL) date-time field, Update Table_name set STATUS_DATE= STR_TO_DATE(substring_index(SSTATUS_DATE," ",1),'%c/%e/%Y'), somewhere in the table I have bad data and the query stops and ...

C++ inline String formatting and numeric conversion

Hello all, C# has a nice static method String.Format(string, params string[]); that returns a new string with the formatting and values that are provided. Is there an equivalent in C++? The reason is because I'm using log4cxx and want to take advantage of the macros like LOG4CXX_DEBUG( logger, expr ); that uses short-circuit ev...

Fast filtering of a string collection by substring?

Do you know of a method for quickly filtering a list of strings to obtain the subset that contain a specified string? The obvious implementation is to just iterate through the list, checking each string for whether it contains the search string. Is there a way to index the string list so that the search can be done faster? ...

C++ .NET convert System::String to std::string

How do you convert System::String to std::string in C++ .NET? ...

Selecting items in a combobox and removing them

Hi, I want to find an Index of a combobox using numbers in the text of a textbox, and then remove them. The items that populate the combobox belong to a data base so I use the Delete method to remove the rows. EDITED: I've been reading and the findstring finds text within the item list, not the index. Is there anyway to look for the ...

cutdown uuid further to make short string

I need to generate unique record id for the given unique string. I tried using uuid format which seems to be good. But we feel that is lengthly. so we need to cutdown the uuid string 9f218a38-12cd-5942-b877-80adc0589315 to smaller. By removing '-' we can save 4 chars. What is the safest part to remove from uuid? We don't need unive...

How do I compare strings in objective c?

I want to compare the value of an NSString to the string "Wrong". Here is my code: NSString *wrongTxt = [[NSString alloc] initWithFormat:@"Wrong"]; if( [statusString isEqualToString:wrongTxt]){ doSomething; } Do I really have to create an NSString for "Wrong"? Also, can I compare the value of a UILabel.text to a string without ...

Python string interpolation using dictionary and strings

Given: dict = {"path": "/var/blah"} curr = "1.1" prev = "1.0" What's the best/shortest way to interpolate the string to generate the following: path: /var/blah curr: 1.1 prev: 1.0 I know this works: str = "path: %(path)s curr: %(curr)s prev: %(prev)s" % {"path": dict["path"],"curr": curr, "prev": prev} But I was hoping there ...

Convert a string array to a concantenated string in C#

Is there an easy way to convert a string array into a concantenated string? For example, I have a string array: new string[]{"Apples", "Bananas", "Cherries"}; And I want to get a single string: "Apples,Bananas,Cherries" Or "Apples&Bananas&Cherries" or "Apples\Bananas\Cherries" ...

Prevent round off in String.format("%.2f", doubleValue) in Java

How do I prevent String.format("%.2f", doubleValue); from rounding off (round half up algorithm) instead of just truncating it? e.g. doubleValue = 123.459 after formatting, doubleValue = 123.46 I just want to discard the last digit, 123.45 I know there are other ways to do this, I just want to know if this is possible using the...

Java regex to match all html elements except one special case

I have a string with some markup which looks like this: The quick brown <a href="www.fox.org">fox</a> jumped over the lazy <a href="entry://id=6000009">dog</a> <img src="dog.png" />. I'm trying to strip away everything except the anchor elements with "entry://id=" inside. Thus the desired output from the above example would be: The qu...

How can I generate pseudo-random "readable" strings in Java?

Generating a truly random string of a given length is a fairly straightforward (and already-well-covered) task. However; I'd like to generate a "pseudo" random string with the additional constraint that it be relatively easily readable (to a native-English reader.) I think another way to say this is to say that the generated string sho...

Python __str__ versus __unicode__

Is there a python convention for when you should implement __str__() versus __unicode__(). I've seen classes override __unicode__() more frequently than __str__() but it doesn't appear to be consistent. Are there specific rules when it is better to implement one versus the other? Is it necessary/good practice to implement both? ...

String split question using "*"

Let's say have a string... String myString = "my*big*string*needs*parsing"; All I want is to get an split the string into "my" , "big" , "string", etc. So I try myString.split("*"); returns java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0 * is a special character in regex so I try escaping.... my...

Pass a string by reference in Javascript

I want to create a string and pass it by reference such that I can change a single variable and have that propagate to any other object that references it. Take this example: function Report(a, b) { this.ShowMe = function() { alert(a + " of " + b); } } var metric = new String("count"); var a = new Report(metric, "a"); var b = new...

javascript substring help.

I have a string "2500 - SomeValue". How can I remove everything before the 'S' in 'SomeValue'? var x = "2500 - SomeValue"; var y = x.substring(x.lastIndexOf(" - "), // this is where I'm stuck, I need the rest of the string starting from here. Thanks for any help. ~ck ...

Python String Formatting And String Multiplication Oddity

Python is doing string multiplication where I would expect it to do numeric multiplication, and I don't know why. >>> print('%d' % 2 * 4) 2222 >>> print('%d' % (2 * 4)) 8 Even forcing the type to integer does nothing. (I realize this is redundant, but it's an idiot-check for me: >>> print('%d' % int(2) * int(4)) 2222 Obviously I ...