Tagged Questions

39
votes
6answers
52k views

How do I split this string with JavaScript?

I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using JavaScript, what is the fastest way to parse this into var name = "john smith"; var street= "123 Street"; //etc...
8
votes
5answers
1k views

C - Difference between “char var[]” and “char *var”?

I am expecting that both following vectors have the same representation in RAM: char a_var[] = "XXX\x00"; char *p_var = "XXX"; But strange, a call to a library function of type f(char argument[]) ...
2
votes
2answers
266 views

String with array structure to Array

I have string: Main.Sub.SubOfSub And some kind of data, may be a string: SuperData Also I have an empty array: $k = array(); How I can transform it all to this array above? Array ( [Main] ...
8
votes
5answers
1k views

Difference between char *str=“STRING” and char str[] = “STRING”?

While coding a simple function to remove a particular character from a string, I fell on this strange issue: void str_remove_chars( char *str, char to_remove) { if(str && to_remove) { ...
24
votes
61answers
16k views

Language showdown: Convert string of digits to array of integers? [closed]

I was trying to convert a string containing only base 10 digits (e.g. "124890") to an array of corresponding integers (for given example: [1, 2, 4, 8, 9, 0]), in Ruby. I'm curious about how easily ...
60
votes
7answers
84k views

How to convert object array to string array in Java

I use the following code to convert an Object array to a String array : Object Object_Array[]=new Object[100]; // ... get values in the Object_Array String String_Array[]=new ...
13
votes
4answers
1k views

Literal string initializer for a character array

In the following rules for the case when array decays to pointer: An lvalue [see question 2.5] of type array-of-T which appears in an expression decays (with three exceptions) into a pointer to ...
3
votes
3answers
14k views

How can I split a comma delimited string into an array in PHP?

I need to split my string input into an array at the commas. How can I go about accomplishing this? Input: 9,[email protected],8
4
votes
3answers
3k views

How to parse JSON in iOS App

Im getting a response from twitter in the form of a string, What I need is to send the parts where is a comment to an array, here an example of the string ...
1
vote
4answers
171 views

use strings to access (potentially large) multidimensional arrays

I am having trouble figuring out a way to simply parse a string input and find the correct location within a multidimensional array. I am hoping for one or two lines to do this, as the solutions I ...
9
votes
7answers
3k views

A quick and easy way to join array elements with a separator (the oposite of split) in Java

See Related .NET question I'm looking for a quick and easy way to do exactly the opposite of split so that it will cause ["a","b","c"] to become "a,b,c" Iterating through an array requires either ...
13
votes
5answers
2k views

length and length() in java

Why do we have length of an array as an attribute. array.length and for String we have a method str.length()? Just came in my mind, is there some reason?
12
votes
3answers
7k views

LINQ: Entity string field contains any of an array of strings

I want to get a collection of Product entities where the product.Description property contains any of the words in a string array. It would look something like this (result would be any product ...
7
votes
6answers
21k views

Java: Comparing two string arrays and removing elements that exist in both arrays

This is mainly a performance questions. I have a master list of all users existing in a String array AllUids. I also have a list of all end dated users existing in a String array EndUids. I am ...
13
votes
4answers
1k views

Check if multiple strings exist in another string

How can I check if any of the strings in an array exists in another string? Like: a = ['a', 'b', 'c'] str = "a123" if a in str: print "some of the strings found in str" else: print "no strings ...
9
votes
16answers
1k views

Algorithm for joining e.g. an array of strings

I have wondered for some time, what a nice, clean solution for joining an array of strings might look like. Example: I have ["Alpha", "Beta", "Gamma"] and want to join the strings into one, separated ...
0
votes
4answers
4k views

PHP get values from SimpleXMLElement array

I have this: [1]=> object(SimpleXMLElement)#6 (1) { ["@attributes"]=> array(14) { ["name"]=> string(5) "MySQL" ["acknowledged"]=> string(1) "1" ["comments"]=> ...
0
votes
8answers
4k views

String to Array and Back

I have a string, how do I convert it to an array? After manipulating that array, how do I again make it into a string? Do strings in PHP behave the same way as in Java? is there a dupe for this?
88
votes
4answers
21k views

Ruby: what does %w(array) mean?

I'm looking at the documentation for FileUtils. I'm confused by the following line: FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6' What does the %w mean? Can you point me to the ...
7
votes
6answers
3k views

C#: Cleanest way to divide a string array into N instances N items long

I know how to do this in an ugly way, but am wondering if there is a more elegant and succinct method. I have a string array of e-mail addresses. Assume the string array is of arbitrary length -- it ...
38
votes
5answers
46k views

convert javascript comma separated string into an array

I have a comma separated string that I want to convert into an array so I can loop through it. Is there anything built-in to do this?
17
votes
6answers
30k views

how to add new elements to a String[] array?

I have a Java code defined as: String[] where; /**/where.append(ContactsContract.Contacts.HAS_PHONE_NUMBER+"=1"); /**/where.append(ContactsContract.Contacts.IN_VISIBLE_GROUP+"=1"); Those two ...
7
votes
7answers
15k views

How do I create an array of strings in C?

I am trying to create an array of strings in C. If I use this code: char (*a[2])[14]; a[0]="blah"; a[1]="hmm"; gcc gives me "warning: assignment from incompatible pointer type". What is the ...
17
votes
6answers
2k views

string.Join on a List<int> or other type

I want to turn an array or list of ints into a comma delimited string, like this: string myFunction(List<int> a) { return string.Join(",", a); } But string.Join only takes ...
12
votes
4answers
15k views

PHP: Split string into array, like explode with no delimiter

I have a string such as: "0123456789" and need to split EACH character into an array. I for the hell of it tried: explode('', '123545789'); But it gave me the obvious: Warning: No delimiter ...
5
votes
1answer
3k views

Marshalling array of strings to char ** in C#. Must be quite easy (if you know how ;-)

I'm calling a C DLL function and need to supply the following C struct: typedef struct { char *mTableId; char **mFieldNames; int mNumFields; char *mFilter; ...
22
votes
4answers
19k views

.NET / C# - Convert char[] to string

Guess I have just never run across it before. What is the proper way to turn a char[] into a string? The ToString() method from an array of chars doesn't do the trick. Guess I had always imagined ...
9
votes
8answers
2k views

When would you use an array rather than a vector/string?

I'm a beginner C++ programmer and so I've learnt using arrays rather than vectors (this seems to be the general way to do things, then move on to vectors later on). I've noticed that a lot of answers ...
6
votes
5answers
12k views

Initializing static array of strings (C++)?

I can't for the life of me figure out how to do this properly. I have a class that needs to store some constants (text that corresponds to values in an enum type) - I have it declared like this ...
3
votes
4answers
14k views

Remove Null Value from String array in java

How to remove null value from String array in java? String[] firstArray = {"test1","","test2","test4",""}; I need the "firstArray" without null ( empty) values like this String[] firstArray = ...
2
votes
6answers
321 views

Counting frequency of a string

I essentially want to search the frequency of a string. For example, if I pass in the word "I", then the frequency of the word in the following sentence: "I went to the beach and I saw three people" ...
6
votes
4answers
1k views

Parse query string into an array

How can I turn a string below into an array? pg_id=2&parent_id=2&document&video This is the array I am looking for, array( 'pg_id' => 2, 'parent_id' => 2, 'document' => , ...
5
votes
8answers
10k views

How to convert a Java String to an ASCII byte array?

How to convert a Java String to an ASCII byte array?
2
votes
6answers
410 views

Why does println(array) have strange output? (“[Ljava.lang.String;@3e25a5”)

I have a string array with four elements in it that I defined. How come when I type System.out.println(name of Array), it doesn't output the elements? But instead gives me a weird output. Here's my ...
2
votes
2answers
121 views

reliably convert string containing PHP array info to array

suppose I have the string $str = "array(1,3,4),array(array(4,5,6)),'this is a comma , inside a string',array('asdf' => 'lalal')"; and I try to explode this into an array by comma so that the ...
2
votes
2answers
4k views

Get text between HTML tags

Ok, This is a pretty basic question im sure but im new to PHP and haven't been able to figure it out. The input string is $data im trying to continue to pull and only use the first match. Is the below ...
2
votes
4answers
4k views

Simplest way to match array of strings to search in perl?

What I want to do is check an array of strings against my search string and get the corresponding key so I can store it. Is there a magical way of doing this with Perl, or am I doomed to using a loop? ...
1
vote
3answers
922 views

problem filling string[] with string-array from strings.xml

EDIT: woah ... somehow i replaced this question with another one i was asking, glad there is this rollback feature this specific question deals with the getter from my previous question public class ...
1
vote
8answers
2k views

Merge array items into string

How do I merge all the array items into a single string?
1
vote
2answers
1k views

Javascript date sorting by convert the string in to date format

How can i convert these strings in to date format and sort accordingly....please 2010-11-08 18:58:50.0_getCreated_10180 2010-11-09 17:49:42.0_getCreated_10180 2010-11-09 ...
1
vote
5answers
965 views

initializing char arrays in a way similar to initializing string literals

Suppose I've following initialization of a char array: char charArray[]={'h','e','l','l','o',' ','w','o','r','l','d'}; and I also have following initialization of a string literal: char ...
0
votes
5answers
117 views

how to edit my compare method

I want to compare contens of my two txt files and write the different words in other file3.txt file I want to do compare method in this way to write another txt file. Also I dont have an error for ...
0
votes
3answers
3k views

For each result in MySQL query, push to array (complicated)

Okay, here's what I'm trying to do. I am running a MySQL query for the most recent posts. For each of the returned rows, I need to push the ID of the row to an array, then within that ID in the array, ...
0
votes
4answers
399 views

Convert a String into an Array of Characters

In PHP, how do i convert: $result = abdcef; into an array that's: $result[0] = a; $result[1] = b; $result[2] = c; $result[3] = d;
0
votes
2answers
525 views

Problem with processing individual strings stored in an array of pointers to multiple strings in C

An array of pointers to strings is provided as the input. The task is to reverse each string stored in the input array of pointers. I've made a function called reverseString() which reverses the ...
0
votes
2answers
429 views

Find length of initial segment matching mask on Arrays

Given an array with n values, for example: $arr[] = 'ABCDEFABC'; $arr[] = 'ABCDEFDEF'; $arr[] = 'ABCDEFGHI'; $arr[] = 'ABCDEFJKL'; how can I find the initial segment that matches all (or most, in ...
272
votes
12answers
17k views

Why does [1,2] + [3,4] = “1,23,4” in JavaScript?

I wanted to add the elements of an array into another, so I tried this simple sentence in our beloved Firebug: [1,2] + [3,4] It responded with: "1,23,4" What is going on?
23
votes
7answers
32k views

Using C# to check if string contains a string in string array

I want to use C# to check if a string value contains a word in a string array. For example, string stringToCheck = "text1text2text3"; string[] stringArray = ("text1", etc... ) ...
10
votes
3answers
1k views

Finding the first non-repeated character of a string in O(n) using a boolean array?

My question is related to this earlier question Find the first un-repeated character in a string. In one of my interviews I was asked to write a function to determine the first unique character ...
6
votes
6answers
2k views

The Most Efficient Algorithm to Find First Prefix-Match From a Sorted String Array?

Input: 1) A huge sorted array of string SA; 2) A prefix string P; Output: The index of the first string matching the input prefix if any. If there is no such match, then output will be -1. ...

1 2 3 4
15 30 50 per page