string

How do I check if a C++ <string> starts with a certain string, and convert a substring to an int?

How do I do the following (Python pseudocode) in C++? if argv[1].startswith('--foo='): foo_value = int(argv[1][len('--foo='):]) (For example, if argv[1] is '--foo=98', then foo_value is 98.) Update: I'm hesitant to look into Boost, since I'm just looking at making a very small change to a simple little command-line tool. (I'd ra...

String comparing in c#

Hi, I want to compare two strings for any match ie; my two string are string1 = "hi i'm tibinmathew @ i'm fine"; string2 = "tibin"; I want to compare the above two string. If there is any match found i have to execute some statements. I want to do this in c#. How can I do this? ...

How to exclude more than one character in rule?

I'm trying to write a string matching rule in ANTLRWorks, and i need to match either escaped quotes or any non quote character. I can match escaped quotes but I'm having trouble with the other part: ~'\'' | ~'\"' will end up matching everything and ~'\'\"' seems to be ignored by the grammar generator (at least the visual display). What s...

how to generate a stream from a string ?

I need to write a unit test for a method that takes a stream which comes from a txt file, I would like to do do something like this: Stream s = GenerateStreamFromString("a,b \n c,d"); ...

Finding the first number in a string using .NET 3.5

I have a bunch of strings I need to extract numbers from. They're in the format: XXXX001 XXXXXXX004 XX0234X There's a lot of these, and i need to loop over them all and extract all the numbers. So what's the quickest/most efficient way, using ASP.NET 3.5, to find the first instance of a number within a string? Update I should've inc...

How to extract text before a period from a string in C#?

Say I have a string whose text is something like, "mohdibrahim.tasal". I want to extract "mohdibrahim" from this string. I've tried this code: string updateUser1 = user1.Trim(); Is this the correct approach, or is there another technique I should be using? ...

Decoding packed data into a structure

Hi What would the best way of unpacking a python string into fields I have data received from a tcp socket, it is packed as follows, I believe it will be in a string from the socket recv function It has the following format uint8 - header uint8 - length uint32 - typeID uint16 -param1 uint16 -param2 uint16 -param3 uint16 -param4 char[...

How do I split a string that contains different signs?

I want to split a string that can look like this: word1;word2;word3,word4,word5,word6.word7. etc. The string is from an output that I get from a php page that collects data from a database so the string may look different but the first words are always separated with ; and then , and the last words with .(dot) I want to be able to fet...

C - Difference between "char var[]" and "char *var" ?

I am expecting that both following vectors have the same representation in RAM: char a_var[] = "XXX\x00"; char *p_var = "XXX"; But strange, a call to a library function of type f(char argument[]) crushs the running application if I call it using f(p_var). But using f(a_var) is Ok! Why? ...

Questions about Java's String pool

Consider this code: String first = "abc"; String second = new String ("abc"); When using the new keyword, Java will create the abc String again right? Will this be stored on the regular heap or the String pool? How many Strings will end in the String pool? ...

String comparison equivalents

I believe these 2 lines are equivalent but after running into a strange issue I no longer believe this to be the case. String mimeType = context.Request.ContentType; (String.Compare("text/xml", mimeType, true) == 0)) is the same as : context.Request.ContentType.ToLower().Equals("text/xml") Are their implementations in the CLR any d...

PHP Cannot escape my string properly

I'm using mysql_real_escape_string to escape my content but I am receiving an error in a SQL INSERTION QUERY for having a single-quote unescaped. How can I resolve this? $content = mysql_real_escape_string("'content'",$conn); The error message I am receiving is: You have an error in your sql syntax near 'content My SQL Query ENDS U...

Find the nth occurrence of substring in a string

This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way. I want to find the n'th occurrence of a substring in a string. There's got to be something equivalent to what I WANT to do which is mystring.find("substring", 2nd) How can you achieve this in Python? ...

Format double with no decimal point

Hi, I've to convert double to 10 digits + 4 decimal. so let say: I have a double 999,56. I've to get 00000009995600 -> without comma! What I have is: string.format("{0:0000000000.0000}", value) but what I get is: 0000000999,5600 so what I can do now is to search for the comma and delete it, but I would like to know if there is anoth...

Recommendation sought for basic string difference algorithm

Hello, I'm looking for an algorithm that takes as arguments two strings, source and destination, and returns the steps required to transform the source string to the destination. Something that takes Levenshtein distance one step farther. E.g., Input: source "abc", dest "abbc" Output: insert 'b' at position 1 in source Input: source...

How do I un-escape a backslash-escaped string in python?

Suppose I have a string which is a backslash-escaped version of another string. Is there an easy way, in Python, to unescape the string? I could, for example, do: >>> escaped_str = '"Hello,\\nworld!"' >>> raw_str = eval(escaped_str) >>> print raw_str Hello, world! >>> However that involves passing a (possibly untrusted) string to ev...

Passing C++ strings by value or by reference

I'm wondering whether the C++ string is considered small enough to be more efficient when passed by value than by reference. ...

How to do a string replace in a urlencoded string

I have a string like x = "http://query.yahooapis.com/v1/public/yql?q=select%20owner%2Curls%20from%20flickr.photos.info%20where%20photo_id%3D'%s'&amp;format=json" If I do x % 10 that fails as there are %20f etc which are being treated as format strings, so I have to do a string conactination. How can I use normal string replacements here...

Java - string declaration occupying multiple lines?

I am using Java. Inside a Java program I am writing a SQL query: string query = "select * from tableA" ; However sometimes the query is really large. In those cases I want to write the query in different lines e.g.: string query = "select blah1, blah2 blah3, blah4 blah5, blah6 ...

iphone: send back string value with navigationcontroller pop

Hi.. This may be very basic, but I just can`t figure out what to do, so thanks for any response... I`m using a navigationcontroller and are currently on the second level in the stack. Here i set a string value and use popViewControllerAnimated to go back to first level in the stack. What might be the best solution to use that string...