Python - efficient method to remove all non-letters and replace them with underscores.
def format_title(title): ''.join(map(lambda x: x if (x.isupper() or x.islower()) else '_', title.strip())) Anything faster? ...
def format_title(title): ''.join(map(lambda x: x if (x.isupper() or x.islower()) else '_', title.strip())) Anything faster? ...
Hi, I would like to check if a string begins with "node" e.g. "node001". Something like if [ $HOST == user* ] then echo yes fi How can I do it correctly? Thanks! UPDATE: Thank you so much! I further need to combine expressions to check if HOST is either "user1" or begins with "node" if [ [[ $HOST == user1 ]] -o [[ $HO...
From the documentation of the StringPiece class in Chromium's source code: // A string-like object that points to a sized piece of memory. // // Functions or methods may use const StringPiece& parameters to accept either // a "const char*" or a "string" value that will be implicitly converted to // a StringPiece. // // Systematic usag...
A label printer is controled by sending a string of raw ASCII characters (which formats a label). Like this: string s = "\x02L\r" + "D11\r" + "ySWR\r" + "421100001100096" + date + "\r" + "421100002150096" + time + "\r" + "421100001200160" + price + "\r" + "E\r"; RawPrinterHelper.SendStringToPrinter(printerName, s); This hardcoded v...
Is there a way to know whether the element in a string in C has a value or not? I have tried using NULL, '', and ' ', but they don't seem to be working. I need to shift the characters down to index 0 without using stdlib functions. #include <stdio.h> int main() { char literal[100]; //literal[99] = '\0' literal[98] = 'O'; ...
I was playing around today with some timing code and discovered that when asigning a string literal to std::string, that it was around 10% faster (with a short 12 char string, so likly even bigger difference for large strings) to do so with a literal of known length (using the sizeof operator) than not. (Only tested with the VC9 compiler...
If i have a string as such "I am not here... \n..Hello\n.\n....Whats happening" I want to replace the above string so: "I am not here... \n..Hello\n. \n....Whats happening" ^ Space added Just a bit of a background on what im doing. Im using sendmail in C++ and \n.\n is End Of Message Equivalent of sen...
Hi all, [dbo].[Regex]('^[-a-zA-Z0-9,&''.@#/:;]+$',@ClaimantMailingAddressLine1) above is my regular expression when i am passing '(' or ')'brackets symbol it is nt returnig error... please hw 2 do this.... and please teach me how to eliminate perticular character is a invalid thing. rite now wt ever symbol is present in brackets i.e...
In an interview question, Interviewer asked me What is the common and difference between the following statements: String s = "Test"; String s = new String("Test"); Is there any difference in memory allocation? ...
Hi, I have a string that is quite long and complicated, with special characters inside. I want to define this string as a variable, but don't want to escape each of them (because there are so many). I remember that in XML they have a special syntax for that, is there something similar for Objective-C? Edit: I know I can save the thing ...
Hi, my question is about how to use bitwise operators on C++ std::string... through overloading or as function does not matter Example for an working XOR/^ function for std::string: std::string XOR(std::string value, std::string key) { std::string retval(value); long unsigned int klen = key.length(); long unsigned int vlen = val...
I am writing a simple parser that will take a string of the format 20100101,1,2,foo and create an instance of the following class: public class Foo { public DateTime TheDate { get; set; } public int TheFirstInt { get; set; } public int TheSecondInt { get; set; } public string TheString { get; set; } } I would like to b...
I am using the .NET DateTime to get the current date and time. I am converting it to a string to use as part of a file name. The problem is the OpenCV command to save an image requires a char * not a string type, and DateTime will only output a String^ type. How do I make this work? Heres the code not completed String^ nowString = DateT...
I know several (all?) STL implementations implement a "small string" optimization where instead of storing the usual 3 pointers for begin, end and capacity a string will store the actual character data in the memory used for the pointers if sizeof(characters) <= sizeof(pointers). I am in a situation where I have lots of small vectors wit...
I tried different things but i'm getting mad with Interop. (here the word string is not referred to a variabile type but "a collection of char"): I have an unmanaged C++ function, defined in a dll, that i'm trying to access from C#, this function has a string parameter and a string return value like this: string myFunction(string input...
How can i show this? substring?split? ... but it's maybe dynamic !!! String str = "SET ENCALSUP=NOENCR&GSMV2,MAXNCELL=16,TDTMWIND=5,MAXLAPDMN=5,EENHDTMSUP=DISABLED,T3197=4,PAGCOORCLB=DISABLED,DGRSTRGYBCNT=DISABLED,PAGQOVLIND=0;"; this output (EENHDTMSUP=DISABLED): just this DISABLED Thanks ... ...
I need to escape a & character in a string. The problem is whenever I string = string.replace ('&', '\&') the result is '\\&'. An extra backslash is added to escape the original backslash. How do I remove this extra backslash? ...
Trying to only print if a string isn't empty, and am using the code below, but it keeps coming up with that error... <%if(!String.IsNullOrEmpty(o_handler.renderDesc())) { %> <strong>Description:</strong><BR> <HR SIZE="1"> <strong><%= o_handler.renderDesc()%></stro...
Is there a C function to find the second occurrence of sub-string in string? i.e. String - "213 File status 550 Access Denied. 550 Access Denied." This function would return "550 found twice".... ...
I can't get my head around quotes. EG, I have a string for an mp3 with quotes: string ARTIST = "John \"The Man\" Doe" I then want to pass this to a command line WITH the escape sequences. I therefore need my string to look like (I think): ARTIST = "John \\\"The Man\\\" Doe" So it looks like, for every time I have an (actual) " in ...