string

Android java datetime values from String to Long to String issue

Long time reader, first time poster. In Android, capturing date from datepicker and storing as string in sqlite. Sorting by date doesn't work because they're strings (unless I'm doing it wrong. I've googled this issue for ~5 days, and it looks like there should be a way to capture the date from the date picker, convert it to a Long, s...

Splitting string into an array in PHP

Hello, I want split a string which consists of products. Each product is encloded within {..}, and separated by comma. For instance, I have a strin below. [ {\"productid\" : \"prod:kj42j3d24-47c2-234lkj2-e3c2-cfc9a4a3b005\",\"memo\" : \" product description \",\"taxable\" : 0,\"unitweight\" : 0,\"unitcost\" : 0,\"unitprice\" : 12.34,...

Java's String.replace() vs. String.replaceFirst() vs. homebrew

I have a class that is doing a lot of text processing. For each string, which is anywhere from 100->2000 characters long, I am performing 30 different string replacements. Example: string modified; for(int i = 0; i < num_strings; i++){ modified = runReplacements(strs[i]); //do stuff } public runReplacements(String str){ str = str....

String formatting in Java

I've been using python too much lately and I forget if there's a way to do this in Java: print "I am a %s" % string I googled, but it's hard to find simple stuff like this when you don't know exactly what this is called in each language. ...

Android: Cursor results to String[]

I have a query in my android app that pulls all image paths from a custom table and displays them to a gallery. The problem is with my database I cant seem to get a row of the database to a String[]. I can easily get the results to a listArray but I need the image path in a string or string array. I want to be able to click on an image...

Static C string allocation question

Consider the following code: char* str = "Hello World"; memcpy(str, "Copy\0", 5); A segmentation fault occurs during the memcpy. However, using this code: char str[12]; memcpy(str, "Hello World\0", 12); memcpy(str, "Copy\0", 5); The program does not produce a segmentation fault. Does the problem arise from allocating the memory on...

Excel/VBA: How to paste SQL query with proper string formatting

Hi folks, I've been writing some pretty long SQL queries in notepad and then pasting them into my VBA code as-is and then formatting the multi-line string correctly each line at a time. For example... In my text editor, the query looks like this. SELECT a, b, c, ..., n FROM table1, table2, ...

Interpreting a Java String

Is there any way to to interpret a string such as "hello\r\n\world" into a string where \r\n has been converted into their actual literal values. The scenario is that a user types in a regex replacement expression and types \r\n in the UI. That get's escaped but I'd like to get the actual interpreted string from that. ...

Remove empty strings from a list of strings

I want to remove all empty strings from a list of strings in python. My idea looks like this: while '' in str_list: str_list.remove('') Is there any more pythonic way to do this? ...

How to print in a thread-safe manner in C/Cilk?

I am playing around with Cilk and I am having an issue with printing synchronously. Printing is slow, so it's hard to keep the prints synchronous. For example... void ftn(int x) { if (x % 2 == 0) { std::cout << "printing.. " << x << std::endl; } else { cilk_spawn ftn(x/2); cilk_spawn ftn(x++...

how to find string length using strlen in objective c

i have a string strored in str variable i want to find string length which is available in str variable i hav tried with strlen(str); its not working... ...

How can I replace aeiou with bfjpv in Perl?

I want to replace aeiou with bfjpv in user inputted string. Here is the code which is not working :- print "Enter any String :"; while(($string = <>) ne "\n"){ @arr = split(//,$string); for($i = 0 ; $i < $#arr ; $i++){ $char = $arr[$i]; if($char eq 'a' || $char eq 'e' || $char eq 'i' || $char eq 'o' || $char e...

How to store a concatenation of ints and characters in a char*?

I have some integers, let's say one two and three. I wish to create a string such as char* example = "There are " + one + " bottles of water on " + two + " shelves in room number " + three + "\n".` This doesn't work in C/C++. How can I store that type of value in a char*? ...

Is there a formal definition of character difference across a string and if so how is it calculated?

Overview I'm looking to analyse the difference between two characters as part of a password strength checking process. I'll explain what I'm trying to achieve and why and would like to know if what I'm looking to do is formally defined and whether there are any recommended algorithms for achieving this. What I'm looking to do Across ...

Java: Change String[][] Dynamically

I have this code: newArray = new String[][]{{"Me","123"},{"You","321"},{"He","221"}}; And I want to do this dynamically. Add more elements, things like it. How do I do this? PS: Without using Vector, just using String[][]; ...

php getting substring from a string.

I have the next URL: http://domen.com/aaa/bbb/ccc. How can I get the string after http://domen.com/? Thanks a lot. ...

Storing NULL characters (ASCII 0)

I've created a program in C++ that prompts the user for a filename and for the requested filesize. The program checks if the requested filesize is bigger than the actual filesize and then adds null characters (the ones with code 0) at the end of the file, until the requested filesize is reached. I have done it like this (with fstream): ...

How to make clear to user that the function's argument to be entered as string in Matlab?

I have the following function whose last argument is a name of the text file: function [property_without_headers]=gslib_file_to_matlab_var(nModel,nCell,gslib_file_name) % must enter the last argument, gslib_file_name, in single quotes as its treated as a string if nargin<3, % making third argument optional (code to be executed even whe...

Returning strings from functions that are of unexpected length?

C is always pretty awkward with strings, but it's usually okay to just allocate a char array of size 256 for your string and be on with it. However, what if you want the function to return a string and you don't know the size, since you will be concatenating strings together dozens or hundreds of times? Obviously something like this ...

Python: Why Lists do not have a find method?

I was trying to write an answer to this question and was quite surprised to find out that there is no find method for lists, lists have only the index method (strings have find and index). Can anyone tell me the rationale behind that? Why strings have both? ...