string-manipulation

C++ exam question on string class implementation

I just took an exam where i was asked the following: Write the function body of each of the methods GenStrLen, InsertChar and StrReverse for the given code bellow. You must take into consideration the following; How strings are constructed in C++ The string must not overflow Insertion of character increases its length by ...

Speed vs security vs compatibility over methods to do string concatenation in Python

Similar questions have been brought (good speed comparison there) on this same subject. Hopefully this question is different and updated to Python 2.6 and 3.0. So far I believe the faster and most compatible method (among different Python versions) is the plain simple + sign: text = "whatever" + " you " + SAY But I keep hearing and r...

Convert Dashes to CamelCase in PHP

Can someone help me complete this PHP function? I want to take a string like this: 'this-is-a-string' and convert it to this: 'thisIsAString': function dashesToCamelCase($string, $capitalizeFirstCharacter = false) { // Do stuff return $string; } ...

Is there a function akin to fprintf but only returns the result of formated string in C?

fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf); I don't want to output anything via fprintf,but only the result of "Error in pcap_findalldevs: %s\n", errbuf,what's the function for that? ...

ruby enclose selected whole words in brackets

@string = "Sometimes some stupid people say some stupid words" @string.enclose_in_brackets("some") # => "Sometimes {some} stupid people say {some} stupid words" How should the method enclose_in_brackets look ? Please keep in mind, I want only enclose whole words, (I don't want "{Some}times {some} stupid....", the "sometimes" word shou...

C# null terminated string

I am communicating with a server who needs null terminated string How can I do this smartly in C#? ...

Nokogiri find text in paragraphs

I want to replace the inner_text in all paragraphs in my XHTML document. I know I can get all text with Nokogiri like this doc.xpath("//text()") But I want only operate on text in paragraphs, how I can select all text in paragraphs without affecting eventually existent anchor texts in links ? #For example : <p>some text <a href="/">...

php string to array and split

Hi folks Looking for suggestions as to the best way to do this (I know there are many options): take a variable like this: $args = ('post_type=post&order_by=DESC&limit=10'); the create a function to convert that variable into parts like this: $post_type = post; $order_by = DESC; $limit= 10; Reason is I want a client to be able to...

C++ stringstream reads all zero's

I have a file which contains three integers per line. When I read the line I use a stringstream to separate the values, but it only reads the first value as it is. The other two are read as zero's. ifstream inputstream(filename.c_str()); if( inputstream.is_open() ){ string line; stringstream ss; while( getline(inputstream...

JavaScript: Given an offset and substring length in an HTML string, what is the parent node?

My current project requires locating an array of strings within an element's text content, then wrapping those matching strings in <a> elements using JavaScript (requirements simplified here for clarity). I need to avoid jQuery if at all possible - at least including the full library. For example, given this block of HTML: <div> <p>T...

string.EndsWith()

I need to check in string.Endswith("") from any of the following operators: "+,-,*,/" If I have 20 operators I don't want to use "||" operator 19 times. ...

Remove leading zero's from alphanumeic text

I've seen questions to prefix zeros here in SO. But not the other way !! Can you guys suggest me how to remove the leading zeros in alphanumeric text. Are there any built-in APIs or do I need to write a method to trim the leading zero's? Example: 01234 converts to 1234 0001234a converts to 1234a 001234-a converts to 1234-a 101234 rema...

regular expression search in python

Hello all, I am trying to parse some data and just started reading up on regular Expressions so I am pretty new to it. This is the code I have so far String = "MEASUREMENT 3835 303 Oxygen: 235.78 Saturation: 90.51 Temperature: 24.41 DPhase: 33.07 BPhase: 29.56 RPhase: 0.00 BAmp: 368.57 BPot: ...

Remove specific HTML tags and non-ASCII characters

How can I remove <table>, <tr>, and <td> HTML tags plus non-ASCII characters from a string using C#? I want to leave other tags in the string alone. ...

Application leaking Strings?

My .net application does some heavy string loading/manipulation and unfortunately the memory consumption keeps rising and rising and when looking at it with a profiler I see alot of unreleased string instances. Now at one point of time or another I do need all objects t hat do have these string fields, but once done, I could get rid of e...

Get version number from String in Javascript?

I have a version number with 3 digits as a String, var version = "1.2.3"; and would like to compare it to another version. To see if version is newer than otherversion, var otherVersion = "1.2.4"; How would you do it? ...

Best way to code this, string to map conversion in Groovy

I have a string like def data = "session=234567893egshdjchasd&userId=12345673456&timeOut=1800000" I want to convert it to a map ["session", 234567893egshdjchasd] ["userId", 12345673456] ["timeout", 1800000] This is the current way I am doing it, def map = [:] data.splitEachLine("&"){ it.each{ x -> def object = x.s...

String parsing with regular expressions

I have a following string that I would like to parse into either a List or a String[]. (Test)(Testing (Value)) End result should be Test and Testing (Value) ...

How do I coalesce a sequence of identical characters into just one?

Suppose I have this: My---sun--is------very-big---. I want to replace all multiple hyphens with just one hyphen. ...

C Check Substring of a String C

I'm trying to check whether or not the second argument in my program is a substring of the first argument. The problem is that it only work if the substring starts with the same letter of the string. EDIT: It must be done in C, not C++. Sorry int main(int argc, char **argv){ if (argc != 3) { printf ("Usage: check <string o...