string

C String Concatenation

I'm working in C and I have to concatenate a few things. Right now I have this: message = strcat("TEXT " + var); message2 = strcat(strcat("TEXT ", foo), strcat(" TEXT ", bar)); Now if you have experience in C I'm sure you realize that this gives you a Segmentation Fault when you try to run it. So how do i work around that? ...

In Java how do a read/convert an InputStream in to a string?

If you have java.io.InputStream object how should you process that object and produce a String? Suppose I have an InputStream that contains text data, and I want to convert this to a String (for example, so I can write the contents of the stream to a log file). What is the easiest way to take the InputStream and convert it to a Strin...

What are some of the drawbacks to using C-style strings?

I know that buffer overruns are one potential hazard to using C-style strings (char arrays). If I know my data will fit in my buffer, is it okay to use them anyway? Are there other drawbacks inherent to C-style strings that I need to be aware of? EDIT: Here's an example close to what I'm working on: char buffer[1024]; char * line = N...

What's a good way for figuring out all possible words of a given length.

I'm trying to create an algorithm in C# which produces the following output strings: AAAA AAAB AAAC ...and so on... ZZZX ZZZY ZZZZ What is the best way to accomplish this? public static IEnumerable<string> GetWords() { //Perform algorithm yield return word; } ...

sprintf in C#?

Is there something similar to sprintf() in C#? I would for instance like to convert an integer to a 2-byte byte-array. Something like: int number = 17; byte[] s = sprintf("%2c", number); ...

STL String to lower case

Hi, I want to convert an STL String to lowercase. I am aware of the function tolower() however in the past I have had issues with this function and it is hardly ideal anyway as use with a string would require iterating through each character. Is there an alternative which works 100% of the time? ...

How to build query string with Javascript

Just wondering if there is anything built-in to Javascript that can take a Form and return the query parameters, eg: "var1=value&var2=value2&arr[]=foo&arr[]=bar..." I've been wondering this for years. ...

Newbie Python question about strings with parameters: "%%s"?

I'm trying to figure out what the following line does exactly - specifically the %%s part? cursor.execute('INSERT INTO mastertickets (%s, %s) VALUES (%%s, %%s)'%sourcedest, (self.tkt.id, n)) Any good mini-tutorial about string formatting and inserting variables into strings with Python? ...

How do you validate that a string is a valid IP address in C++?

I don't need to validate that the IP address is reachable or anything like that. I just want to validate that the string is in dotted-quad (xxx.xxx.xxx.xxx) fomat, where xxx is between 0 and 255. ...

Init Structure with std::wstring

I've got a structure as follows: typedef struct { std::wstring DevAgentVersion; std::wstring SerialNumber; } DeviceInfo; But when I try to use it I get all sorts of memory allocation errors. If I try to pass it into a function like this: GetDeviceInfo(DeviceInfo *info); I will get a runtime check error complaining that I ...

Null \u0000 in Java String?

Are there any good reasons not to use \u0000 as a delimiter within a Java String? I would be encoding and decoding the string myself. This is for saving a list of user-inputted (I'm expecting input to be typed?) strings to an Eclipse preference and reading it back. The list may be variable size so I don't think I can save each item to i...

Help on string handling in C

In a program to find whether the given number is an Armstrong number, I stored the input no (3 digit) as string as follows. char input[10]; scanf("%s",&input); Now I have to calculate cube of each digit by using pow method of math.h as follows. int a; a = pow(input[0],3); By coding like this, I could not get correct result. If I p...

trimming a string in a JSTL expression

I have the following line in a JSP page: <c:if test="${postAuditBean.postAudit.authority == authority.value}"> I would like change this comparison to first trim leading and trailing spaces from both the left and right hand expressions prior to comparison... as in something like this: <c:if test="${trim(postAuditBean.postAudit.authori...

Highlight the difference between two strings in PHP

Hi, What is the easiest way to highlight the difference between two strings in PHP? I'm thinking along the lines of the Stack Overflow edit history page, where new text is in green and removed text is in red. If there are any pre-written functions or classes available, that would be ideal. Thanks in advance. ...

ASP.NET 3.5 bind to xml string

With ASP.NET 3.5 I can easily bind to an xml file by using an XmlDataSource. How do I bind to an xml string instead of a file? ...

Splitting a string by space in C

I'm working with C and through a socket I will be receiving a message with one space in it, I need to split the string into parts at the space. How would I go about doing this? ...

Best way to convert Pascal Case to a sentence

What is the best way to convert from Pascal Case (upper Camel Case) to a sentence. For example starting with "AwaitingFeedback" and converting that to "Awaiting feedback" C# preferable but I could convert it from Java or similar. ...

Can I convert a C# string value to an escaped string literal

In C#, can I convert a string value to a string literal, the way I would see it in code? I would like to replace tabs, newlines, etc. with their escape sequences. If this code: Console.WriteLine(someString); produces: Hello World! I want this code: Console.WriteLine(ToLiteral(someString)); to produce: \tHello\r\n\tWorld!\r\n ...

C++ Strings Modifying and Extracting based on Separators

Kind of a basic question but I'm having troubles thinking of a solution so I need a push in the right direction. I have an input file that I'm pulling in, and I have to put it into one string variable. The problem is I need to split this string up into different things. There will be 3 strings and 1 int. They are separated by a ":". ...

Flex Mxml and property as string, escaping ?? Help

Hi, A simple problem: If i use escape characters for a property such as <mx:Image id="img" toolTip="\\foo{\\bar}" It wont validate toolTip and therefore not compile. What is the solution ? ...