string

String arrays in c

I wrote a code to read files What is wrong in the following code I am always getting last filename if I print any arrayItem #include <stdio.h> #include <string.h> char **get_files() { FILE *fp; int status; char file[1000]; char **files = NULL; int i = 0; /* Open the command for reading. */ fp = popen("ls"...

System.Text.Encoding.UTF8.GetBytes(s) different values for a string on the same computer, different programs.

I'm doing a System.Text.Encoding.UTF8.GetBytes(s) on a string in two different programs (one console, one web) using .NET 2.0 framework and the encoding is coming back different from the two. For the string "everything" I get the same result, but for the string "OnI3UwUc" I get two different results. For The "OnI3UwUc", 6f6e69337577...

PHP str_replace not working correctly

Hi, I'm using str_replace and it's not working correctly. I have a text area, which input is sent with a form. When the data is received by the server, I want to change the new lines to ",". $teams = $_GET["teams"]; $teams = str_replace("\n",",",$teams); echo $teams; Strangely, I receive the following result Chelsea ,real ,Barcelon...

String replacement in java, similar to a velocity template

Is there any String replacement mechanism in Java, where I can pass objects with a text, and it replaces the string as it occurs. For example, the text is : Hello ${user.name}, Welcome to ${site.name}. The objects I have are "user" and "site". I want to replace the strings given inside ${} with its equivalent values from the obje...

Checking For Equal Instances of 2 Different (Included Example)

I use the == in the code below and prints out "Equals!", why? Can someone explain why these two different strings a and b are equal? public class test { public static void main() { String a = "boy"; String b = "boy"; if(a == b) { System.out.println("Equals!"); } else ...

Reading data from server script using URL

I am calling a login script on the server using http call from iphone. the script returns a string "Invalid" or "valid" based on given username/pswd. Here is what I am using: NSString *myurlstr = [[NSString alloc] initWithFormat:@"http://www.mysite.com/iph/login.aspx?username=%@&amp;password=%@",uname,pswd]; NSString *resultstr = [NS...

Why is string a reference type?

Why is string a reference type, even though it's normally primitive data type such as int, float, or double. ...

dynamic String using String.xml?

is it possible to have a string value in string.xml of the sort " some string PLACEHOLDER1 some more string" so that the place holders can be assigned the value at run time. ...

Free char pointer in c

I am trying to find out filetypes using c code, here is the code char *get_file_type(char *path, char *filename) { FILE *fp; char command[100]; char file_details[100]; char *filetype; sprintf(command, "file -i %s%s", path, filename); fp = popen(command, "r"); if (fp == NULL) { printf("Failed to run c...

inverted comma and string in python..

I'm kinda' new to python, but I have already written many programs including some like download-managers, games and text-editors which require a lot of string manipulation. For representing a string literal I use either single or double inverted commas.. whichever comes to my mind first at that time. Although I haven't yet faced any tro...

JSON strings and how to handle escaped characters

I am using the official JSON library for my java project ad i have noticed something weird. If i have a json such as this: { "text": "This is a multiline\n text" } And i try to get the string like this: System.out.println(jsonObject.getString("text")); I get this on the output: This is a multiline\n text Instead of : This is...

Is it possible to change strings (content and size) in Lua bytecode so that it will still be correct?

Is it possible to change strings (content and size) in Lua bytecode so that it will still be correct? It's about translating strings in Lua bytecode. Of course, not every language has the same size for each word... ...

How to implement a "EndsWith" on a string?

I have a string var s1 = "a,$,b,c"; I want to check if another string ends with s1 So if I send these strings it has to return true w,w,a,$,b,c ^,^,^,$,@,#,%,$,$,a,$,b,c a,w,e,q,r,f,z,x,c,v,z,$,W,a,$,b,c And for these false a,$,b,c,F,W a,$,b,c,W a,$,b,c,$,^,\,/ How can I check it? ...

Interpolation search on strings

For those of you not familiar with interpolation search, it is method to search for a value in a sorted array that is potentially faster than binary search. You look at the first and last element and (assuming that the contents of the array are uniformly distributed) linearly interpolate to predict the location. For example: we have an ...

Android Eclipse - error trying to open or edit /res/values/strings.xml - NullPointerException

getting error: An error has occurred. See error log for more details. java.lang.NullPointerException when I attempt to edit this file in my eclipse Android sdk project. Not seeing anything in LogCat or the Console. I need to update this file to rename the Project. ...

how do i define a constant in a string in PHP?

Hi, I am using a constant NEWS_POST_NUMBER and i am getting confused on how to attach it to a string to query it to database. i tried many things and it is giving errors. here is the string i tried. $query = " SELECT news.id, news.timestamp, news.title FROM news ORDER BY id DESC LIMIT $from, NEWS_POST_NUMBER"; please note NEWS_PO...

How to correctly use innerHTML to create an element (with possible children) from a html string?

Note: I do NOT want to use any framework. The goal is just to create a function that will return an element based on an HTML string. Assume a simple HTML Document like such: <html> <head></head> <body> </body> </html> All functions mentioned are in included the head section and all DOM creation/manipulation is done at the end of ...

python: remove substring only at the end of string

i have a bunch of strings some of them have ' rec' i want to remove that only if those are the last 4 characters so another words somestring='this is some string rec' i want it to be: somestring='this is some string' what is the python way to approach this? ...

How to delete part of a CSV string using Ruby?

Hi, I have a string: "116,118,120,130" and will want to delete either the first, last or any value in between upon execution. To to this I was using: "116,118,120,130".gsub('118','') but the problem is the string contains an extra unnessesary comma: "116,,120,130" and if I use "116,118,120,130".gsub(',116','') it will remo...

How to add a parameter to a formatted string function call via a #define function

Hi, I want to create macros that will insert a parameter into a function call. For example, I have function Action() declared below. Action takes as it's inputs an enum for the state number and a formatted string with optional args for the string. I want to define macros so that instead of calling Action( ActionState1, "someText %d"...