string

Printf and hex values

So, I have a value of type __be16 (2 bytes). In hex, the value is represented as 0x0800 or 2048 in decimal. (16^2 * 8) So, when I printf this; I do this: printf("%04X", value); //__be16 value; //Print a hex value of at least 4 characters, no padding. output: 0008 printf("%i", value); //Print an integer. ou...

Need help with RegEx for ranges

I want to be able to use a RegEx to parse out ranges like a Windows Print dialog (such as 1-50,100-110,111,112). The following is my current code and I am not clear on how to parse for the additional commas and numbers. I can parse out the hyphen, but not sure how to do it for additional commas or hyphens private void tboxRowNum_Leave(o...

PHP return empty json string

My html page sends an ajax request (POST) to PHP, PHP echo a json object. Code has been tested and worked fine at my development view. However, after they are uploaded to a VPS hosting server, the returned json string is empty (I used alert() at the response function to display the responseText and found out it was empty). Could som...

faster strlen ?

Typical strlen() traverse from first character till it finds \0. This requires you to traverse each and every character. In algorithm sense, its O(N). Is there any faster way to do this where input is vaguely defined. Like: length would be less than 50, or length would be around 200 characters. I thought of lookup blocks and all but d...

.NET strings and reference type parameters

I was wondering if any one could explain this code to me... public void SomeMethod() { StringBuilder sb = new StringBuilder(); AppendFoo(sb); String foo = sb.ToString(); // foo is "foo" String s = String.Empty; AppendBar(s); String bar = s; // bar is empty } public void AppendFoo(StringBuilder x) { x.Appen...

PHP check to see if a string matches a pattern

If I need a string to match this pattern: "word1,word2,word3", how would I check the string to make sure it fits that, in PHP? I want to make sure the string fits any of these patterns: word word1,word2 word1,word2,word3, word1,word2,word3,word4,etc. ...

String Comparisons - C

Hello all. I'm trying to write a string routine in C, and I keep hitting on the same issue. In C, I have this string: MAMAAMAAALJ If I have this string: AAA How can I determine that AAA is inside of MAMAAMAAAJ? ...

Javascript - How to reverse a string and disappear those commas?

I want to reverse the string like this: "How are you" -> "you are How" Those are the code I typed, it could reverse the string , but it still has comma between strings like "you,are,How" var str = window.prompt("Enter a string"); var tokens = str.split( " " ); document.writeln( tokens.reverse() ); ...

String Manipulation in Objective-C

Gotten a hold on how to fetch and write to variables in Objective-C, now it's time to learn how to do something more useful with them! Right now, I'm primarily trying to figure out how string manipulation works. In particular, I'm looking for the following functions: Concatenation Finding the length of a string (especially multi-byte...

PHP Regular Expression [accept selected characters only]

I want to accept a list of character as input from the user and reject the rest. I can accept a formatted string or find if a character/string is missing. But how I can accept only a set of character while reject all other characters. I would like to use preg_match to do this. e.g. Allowable characters are: a..z, A..Z, -, ’ ‘ User must ...

Converting Array of Java Strings into LaTeX table

I have an two dimension array that contains strings and want to create a LaTeX table with them. The problem is that they could be longer and there has to be line breakes after 15 characters. The Say it's a 2x2 array with contains {{"String11.......String11", "String21"}, {"String12.......String12.......String12.......", "String22.........

setting strings in gdb

c++: int main() { string a = "a"; ... ... } when i debug in gdb: (gdb) set var a = "ok" Invalid cast I run the program and pause at a break point after string a has been initialized. I'm trying to set its value, but it complains about invalid cast. What's the proper syntax for this? ...

Xcode: entering user input when debugging

int main() { cout << "Buy or sell (b/s): " << endl; string buy_sell; cin >> buy_sell; ..... } when i try to step through this in Xcode, i just stops at the cin >> buy_sell line, because it's waiting for the user input. How do i enter the value i want in the debugger so i can move past this? I'm using Xcode 3.2.1. (I k...

how to split a string

i have a string like 123Prefix1pics.zip i want to split it into 123 Prefix1 pics.zip and store them in different variables i m trying to do it in c#,.net jst litle bit confused on how to use split method ...

jQuery how to check if the class name contains a certain value

I would like to read out the classnames attached to a certain element and take action based on that the classname contains a certain value ("active"). The classname could be something like: class="bla-bla-bla first active". What is the best way to do that? ...

Instantiate a new class with the value of a string

Hi. This might be a very stupid question :P But I found this really interessting: class SomeClass{ var $var = "this is some text"; function echoVar($name){ echo $this->{$name}; } } $class = new SomeClass() $class->echoVar("var") // will echo "this is some text" Can I do somethign similar, can I take the value of a string and inst...

Assigning variables based on sting data

Hi Gang, I have a inefficiently constructed form that is obviously sending one type of data per SELECT element. For simplicity's sake, here's an example. The form posts data from 2 SELECT elements, but it actually needs to contain 3 pieces of data. To the user, the SELECTs do contain 3 pieces of data; one SELECT denotes quantity and th...

Arduino String Formatting Issue

I'm making an Arduino-powered clock, and in the process, I'm trying to format integers into two-digit formatted strings for the time read-out (e.g. 1 into "01"). The following gives me "error: expected primary-expression before '{' token": char * formatTimeDigits (int num) { char strOut[3] = "00"; if (num < 10) { strOut = {'0',...

I am trying to determine if a string is a Question. How can I analyze the "?" symbol (python)

This is a question: "Where is the car?" This is NOT a question: "Check this out: http://domain.com/?q=test" How do I write a function to analyze a string so that we know for sure it is a question and not part of a URL? ...

javascript : string contains ...

How can I check if one string contains another substring in Javascript? Usually I would expect a String.contains() method, but there doesn't seem to be one. Edit : thanks for all the answers :) however it seems that I have another problem :( when I use the ".indexof" method, Firefox refuses to start the javascript (this is for an ext...