string

strtoull and long long arithmetic

Can anyone explain the output of this program and how I can fix it? unsigned long long ns = strtoull("123110724001300", (char **)NULL, 10); fprintf(stderr, "%llu\n", ns); // 18446744073490980372 ...

Need a program to reverse the words in a string

I asked this question in a few interviews. I want to know from the Stackoverflow readers as to what should be the answer to this question. Such a seemingly simple question, but has been interpreted quite a few different ways. ...

Javascript: quick script to line up pipe-delimited text (or any-character-delimited text)

Background: I've written this before but I don't like the approach. The reason is because Javascript does not have "sprintf" and that is something I use heavily if the language supports it. Question: How would you use javascript to go from BEFORE to AFTER? If anyone has a solution with very small number of lines of code, or something fr...

Check if at least 75% of a string is UPPERCASE

Hi, I'm writing bug tracking software in PHP, and today I saw this in another bug tracker: http://bugs.php.net/bug.php?id=12017 Now I want to add a feature in my software which will block titles where at least 75% of all characters is uppercase. How can I do this? Thanks, P.S. CSS will not work, because, for example if you have the w...

How to implement Copy-on-Write?

Hey! I want to implement a copy-on-write on my custom C++ String class, and I wonder how to... I tried to implement some options, but they all turned out very inefficient. Thank you guys :-) ...

how to convert CString to Bytes

i am actually tryin to convert a csharp code to c... below is the C# code.. CString data = "world is beautiful"; Byte[] quote = ASCIIEncoding.UTF8.GetBytes(data); in the above code... it converts the string into bytes..similarily is ther a way that i can convert it using C.. Can any body tell what wud be the quivalent code in C? P...

Unicode character categories in Ruby

Is there anything in Ruby that will return me an array of characters belonging to a certain Unicode category? In particular, I'd like to have the Mn category so that I can follow the advice on this answer. ...

reading in numbers using strings

I need to code a function that will take in x numbers. (x is read into the function as an argument) The numbers can be preceded and separated by any number of white spaces and new-lines, and after the last number is entered, a new-line character ends the scan. I thought about using strings the take in characters, and to disregard any non...

In C#, Checking string length greater than zero produces error?

This question sounds outrageous, but VS is giving me an error when I check that a string length is greater than zero: options[j]["pdprice"].ToString().Length > 0 Saying: CS0019: Operator '>' cannot be applied to operands of type 'string' and 'int' Can someone please explain why I cannot check that an integer length property is g...

C#: Snippet extraction based on search term on a single document

I have the text from a PDF document available to me, and I want to display snippets from the text everywhere the user-entered search phrase appears. Say the search term is"iphone", I want to display 200 characters around each iphone word instance in the document. Ideally, the snippet should also start from the beginning of a sentence. ...

Array a string in the following format?

How can i array a string, in the format that $_POST does... kind of, well i have this kind of format coming in: 101=1&2020=2&303=3 (Incase your wondering, its the result of jQuery Sortable Serialize... I want to run an SQL statement to update a field with the RIGHT side of the = sign, where its the left side of the equal sign? I know ...

PHP paginate string problem

i have this script $content = string if(!isset($_GET['page'])){ $page = 1; } else{ $page = $_GET['page']; } while($content[$limit]!= ' '){ $limit++; } print substr($content,($page-1)*$limit, $limit); it works just fine first time (if the page is not set or page number is 1 )but if my page number is greater than 1 it splits my words....

C# Xml Node to String.

I have a XML document with my data in it, multiple entries for the same node fields (StudentID = FirstName, LastName, etc). How do I convert the nodes into string values for each StudentID section? ...

Inserting Escape Characters

I want to replace and insert escape character sequences with their escape character values, also taking into account that '\' nullifies the escape character. For example "This is a \n test. Here is a \\n which represents a newline" What is the easiest way to achieve this in Ruby? ...

C# Match Up XmlNode entry to String text value.

How do I search a xmldata file node for the exact text that I have in my string value. Ie: string fullname = "John Smith" Search XmlData.xml for node "FullName" where the value of the text = "John Smith". Thanks. ...

Java add chars to a string

I have two strings in a java program, which I want to mix in a certain way to form two new strings. To do this I have to pick up some constituent chars from each string and add them to form the new strings. I have a code like this(this.eka and this.toka are the original strings): String muutettu1 = new String(); String muutettu2 = new S...

php how to trim each line in a heredoc (long string)

I'm looking to create a php function that can trim each line in a long string. eg: <?php $txt = <<< HD This is text. This is text. This is text. HD; echo trimHereDoc($txt); output: This is text. This is text. This is text. Yes, I know about the trim() function. Just not sure how to use it on a long strings such a...

PHP Bold some words in a string and remove some unbold words

Hi, I am creating an Image Search Engine. Currently, my script does bold the matching words on the keyword. But, some keywords are too long just like the followings. When I search for shah rukh khan, there is an image with the following keyword. 25216d1235653089 shahrukh khan s wallpaper shah rukh actor As you see, the above k...

Can you tell iostreams which characters to treat as whitespace?

So that you could do something like this, for instance: std::string a("01:22:42.18"); std::stringstream ss(a); int h, m, s, f; ss >> h >> m >> s >> f; Which normally requires the string to be formatted "01 22 42 18". Can you modify the current locale directly to do this? ...

Limit string chars - PHP

I am building an RSS script with mysql, and i dont want an extra field in the database... i want to shrink down the body of the article with a "... Read More" but im not sure how i can limit the number of chars echoed out onto the page? Of course not this syntax, but something along the lines of: echo(limit($row['newsBody'], 1000)); ...