Search Results

Search found 4616 results on 185 pages for 'strings'.

Page 10/185 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • Android Organizing Strings.xml

    - by Neb
    I'm making an android app and since I've just started I want to try get the most organised code/resources. In my strings.xml file so far I have this: <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">GameController</string> <string name="stop">Stop</string> <string name="start">Start</string> <string name="preferences">Preferences</string> <string name="back">Back</string> </resources> All of the strings except app_name are used in an options menu. But since I will be adding much more strings I was thinking that it might be better to do something like this: <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">GameController</string> <string name="menu_stop">Stop</string> <string name="menu_start">Start</string> <string name="menu_preferences">Preferences</string> <string name="menu_back">Back</string> </resources> Is it the best way or should I use another system?

    Read the article

  • Datastructure choices for highspeed and memory efficient detection of duplicate of strings

    - by Jonathan Holland
    I have a interesting problem that could be solved in a number of ways: I have a function that takes in a string. If this function has never seen this string before, it needs to perform some processing. If the function has seen the string before, it needs to skip processing. After a specified amount of time, the function should accept duplicate strings. This function may be called thousands of time per second, and the string data may be very large. This is a highly abstracted explanation of the real application, just trying to get down to the core concept for the purpose of the question. The function will need to store state in order to detect duplicates. It also will need to store an associated timestamp in order to expire duplicates. It does NOT need to store the strings, a unique hash of the string would be fine, providing there is no false positives due to collisions (Use a perfect hash?), and the hash function was performant enough. The naive implementation would be simply (in C#): Dictionary<String,DateTime> though in the interest of lowering memory footprint and potentially increasing performance I'm evaluating a custom data structures to handle this instead of a basic hashtable. So, given these constraints, what would you use? EDIT, some additional information that might change proposed implementations: 99% of the strings will not be duplicates. Almost all of the duplicates will arrive back to back, or nearly sequentially. In the real world, the function will be called from multiple worker threads, so state management will need to be synchronized.

    Read the article

  • Memory usage of strings (or any other objects) in .Net

    - by ava
    I wrote this little test program: using System; namespace GCMemTest { class Program { static void Main(string[] args) { System.GC.Collect(); System.Diagnostics.Process pmCurrentProcess = System.Diagnostics.Process.GetCurrentProcess(); long startBytes = pmCurrentProcess.PrivateMemorySize64; double kbStart = (double)(startBytes) / 1024.0; System.Console.WriteLine("Currently using " + kbStart + "KB."); { int size = 2000000; string[] strings = new string[size]; for(int i = 0; i < size; i++) { strings[i] = "blabla" + i; } } System.GC.Collect(); pmCurrentProcess = System.Diagnostics.Process.GetCurrentProcess(); long endBytes = pmCurrentProcess.PrivateMemorySize64; double kbEnd = (double)(endBytes) / 1024.0; System.Console.WriteLine("Currently using " + kbEnd + "KB."); System.Console.WriteLine("Leaked " + (kbEnd - kbStart) + "KB."); System.Console.ReadKey(); } } } The output in Release build is: Currently using 18800KB. Currently using 118664KB. Leaked 99864KB. I assume that the GC.collect call will remove the allocated strings since they go out of scope, but it appears it does not. I do not understand nor can I find an explanation for it. Maybe anyone here? Thanks, Alex

    Read the article

  • Need some ideas on how to acomplish this in Java (parsing strings)

    - by Matt
    Sorry I couldn't think of a better title, but thanks for reading! My ultimate goal is to read a .java file, parse it, and pull out every identifier. Then store them all in a list. Two preconditions are there are no comments in the file, and all identifiers are composed of letters only. Right now I can read the file, parse it by spaces, and store everything in a list. If anything in the list is a java reserved word, it is removed. Also, I remove any loose symbols that are not attached to anything (brackets and arithmetic symbols). Now I am left with a bunch of weird strings, but at least they have no spaces in them. I know I am going to have to re-parse everything with a . delimiter in order to pull out identifiers like System.out.print, but what about strings like this example: Logger.getLogger(MyHash.class.getName()).log(Level.SEVERE, After re-parsing by . I will be left with more crazy strings like: getLogger(MyHash getName()) log(Level SEVERE, How am I going to be able to pull out all the identifiers while leaving out all the trash? Just keep re-parsing by every symbol that could exist in java code? That seems rather lame and time consuming. I am not even sure if it would work completely. So, can you suggest a better way of doing this?

    Read the article

  • Eclipse on Ubuntu: Rectangles instead of Strings and some Java methods and classes

    - by Claus Hausberger
    after upgrading from Ubuntu 9.04. to 11.04 (new installation), I have weird problems with the Eclipse editor. With the Eclipse PyDev plugin, whenever I typ single quoted strings like 'bla', they appear as rectangles (both the quotes as well as the string). First I thought this was a problem with the PyDev plugin, but it also happens with Java and Scala Plugins. With Java, it happens, for example, when typing System.out.println("bla") and then "out" is shown as rectangles only. Weird is that for about half a second I see "System.out.println" and then the editor changes it to System.[][][].println (not really [] (here I used two brackets), it is shown as rectangles). This is very weird. I've never had this before with any Ubuntu, Java or Eclipse version. Currently, I use: Ubuntu 11.04. Eclipse 3.6 Java 1.6.0_25 The latest plugins for Python (2.1) and Scala (beta 5) where used. Eclipse and Ubuntu Terminal is set to UTF-8. The problem also happens when using KDE instead of Gnome. I doubt is has anything to do with Java as I use the same versions on older Ubuntu installations (10.04, 9.10, etc) at work. It does not happen with Netbeans. But I saw once error dialog message from the Update Manager where there were some rectangles in the error widget. Maybe this is the same problem Any ideas what could be wrong here and how to fix this? Eclipse is unusable but I need this for work and also for Scala and Python (the Eclipse plugins for those are very good now). Claus

    Read the article

  • preg_replace, exact opposite of a preg_match

    - by SoLoGHoST
    I need to do a preg_replace for the exact opposite of this preg_match regular expression: preg_match('#^(\w+/){0,2}\w+\.\w+$#', $string); So I need to replace all strings that are not valid with an empty string - '' So it needs to remove the first / and last / if found, and all non-valid characters, that is the only valid characters are A-Z, a-z, 0-9, _, ., and / (if it's not the first or last characters of the string). How can I accomplish this with the preg_replace? Thanks :)

    Read the article

  • How to dynamically expand a string in C

    - by sa125
    Hi - I have a function that recursively makes some calculations on a set of numbers. I want to also pretty-print the calculation in each recursion call by passing the string from the previous calculation and concatenating it with the current operation. A sample output might look like this: 3 (3) + 2 ((3) + 2) / 4 (((3) + 2) / 4) x 5 ((((3) + 2) / 4) x 5) + 14 ... and so on So basically, the second call gets 3 and appends + 2 to it, the third call gets passed (3) + 2 , etc. My recursive function prototype looks like this: void calc_rec(int input[], int length, char * previous_string); I wrote a 2 helper functions to help me with the operation, but they implode when I test them: /********************************************************************** * dynamically allocate and append new string to old string and return a pointer to it **********************************************************************/ char * strapp(char * old, char * new) { // find the size of the string to allocate int len = sizeof(char) * (strlen(old) + strlen(new)); // allocate a pointer to the new string char * out = (char*)malloc(len); // concat both strings and return sprintf(out, "%s%s", old, new); return out; } /********************************************************************** * returns a pretty math representation of the calculation op **********************************************************************/ char * mathop(char * old, char operand, int num) { char * output, *newout; char fstr[50]; // random guess.. couldn't think of a better way. sprintf(fstr, " %c %d", operand, num); output = strapp(old, fstr); newout = (char*)malloc( 2*sizeof(char)+sizeof(output) ); sprintf(newout, "(%s)", output); free(output); return newout; } void test_mathop() { int i, total = 10; char * first = "3"; printf("in test_mathop\n"); while (i < total) { first = mathop(first, "+", i); printf("%s\n", first); ++i; } } strapp() returns a pointer to newly appended strings (works), and mathop() is supposed to take the old calculation string ("(3)+2"), a char operand ('+', '-', etc) and an int, and return a pointer to the new string, for example "((3)+2)/3". Any idea where I'm messing things up? thanks.

    Read the article

  • Does string concatenation use StringBuilder internally?

    - by JamesBrownIsDead
    Three of my coworkers just told me that there's no reason to use a StringBuilder in place of concatenation using the + operator. In other words, this is fine to do with a bunch of strings: myString1 + myString2 + myString3 + myString4 + mySt... The rationale that they used was that since .NET 2, the C# compiler will build the same IL if you use the + operator as if you used a StringBuilder. This is news to me. Are they correct?

    Read the article

  • How can I hash a string to an int using c++?

    - by zebraman
    I have to write my own hash function. If I wanted to just make the simple hash function that maps each letter in the string to a numerical value (i.e. a=1, b=2, c=3, ...), is there a way I can perform this hash on a string without having to first convert it to a c-string to look at each individual char? Is there a more efficient way of hashing strings?

    Read the article

  • javascript string difference

    - by Konrad
    What is the difference (if any) between the javascript strings defined below? var str1 = "Somestring"; var str2 = 'Somestring'; "" and '' mean two very different things to me predominantly writing code in C++ :-) EDIT: If there is no difference why are there two ways of achieving the same thing and which is considered better practice to use and why. Thanks!

    Read the article

  • PHP preg_match, need some help

    - by SoLoGHoST
    Can someone please help me with this preg_match if (preg_match('~[^A-Za-z0-9_\./\]~', $filepath)) // Show Error message. I need to match a possible filepath. So I need to check for double slashes, etc. Valid file path strings should look like this only: mydir/aFile.php or mydir/another_dir/anyfile.js So a slash at the beginning of this string should be checked also. Please help. Thanks :)

    Read the article

  • Return an empty C-String

    - by Evorlor
    Simple Question: How do you return an empty C-String with as little code as possible? I have code that needs to return an empty char*. I am looking for something along the lines of return "";. I know there are several ways to do this, but I am looking for the most efficient way possible. Using return ""; gives warning: conversion from string literal to 'char *' is deprecated [-Wdeprecated-writable-strings] Thanks!

    Read the article

  • Split large text string into variable length strings without breaking words and keeping linebreaks a

    - by Frank
    I am trying to break a large string of text into several smaller strings of text and define each smaller text strings max length to be different. for example: "The quick brown fox jumped over the red fence. The blue dog dug under the fence." I would like to have code that can split this into smaller lines and have the first line have a max of 5 characters, the second line have a max of 11, and rest have a max of 20, resulting in this: Line 1: The Line 2: quick brown Line 3: fox jumped over the Line 4: red fence. Line 5: The blue dog Line 6: dug under the fence. All this in C# or MSSQL, is it possible?

    Read the article

  • Match beginning of words in Mysql for UTF8 strings

    - by ankimal
    Hi, I m trying to match beignning of words in a mysql column that stores strings as varchar. Unfortunately, REGEXP does not seem to work for UTF-8 strings as mentioned here So, select * from names where name REGEXP '[[:<:]]Aandre'; does not work if I have name like Foobar Aándreas However, select * from names where name like '%andre%' matches the row I need but does not guarantee beginning of words matches. Is it better to do the like and filter it out on the application side ? Any other solutions?

    Read the article

  • Android: dynamically setting links to text in strings.xml

    - by Martyn
    I'm trying to make an app with localisation built in, but I want a way that I can create a web link within the text, the URL being defined elsewhere (for ease of maintenance). So, I have my links in res/values/strings.xml: <?xml version="1.0" encoding="utf-8"?> <resources> ... <string name="link1">http://some.link.com</string> <string name="link2">http://some.link2.com</string> </resources> and my localised text in res/values-en-rGB/strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> ... <string name="sampleText">Sample text\nMore text and link1\nMore text and link2.</string> </resources> I've not tested this bit, but from the localization section of developer.android.com it says that this approach to reducing content duplication should work, although I'm not sure what folder I should put Italian, for example. Would it be in 'res/values-it-rIT/strings.xml'? Lets assume that I have various other languages too. I'm looking for a way of taking the base localised 'sampleText' and inserting my html links in, and getting them to work when clicked on. I've tried two approaches so far: 1, Putting some formatting in the 'sampleText' (%s): <string name="sampleText">Sample text\nMore text and <a href="%s">link1</a>\nMore text and <a href="%s">link2</a>.</string> and then processing the text like this: TextView tv = (TextView) findViewById(R.id.textHolder); tv.setText(getResources().getString(R.string.sampleText, getResources().getString(R.string.link1), getResources().getString(R.string.link2))); But this didn't work when I click on the link, even though the link text is being put in to the correct places. 2, I tried to use Linkify but the regular expression route may be difficult as I'm looking at supporting non-Latin based languages. I tried to put a custom xml tag around the link text and then do something like this: Pattern wordMatcher = Pattern.compile("<span1>.*</span1>"); String viewURL = "content://" + getResources().getString(R.string.someLink); Linkify.addLinks(tv, wordMatcher , viewURL ); But this didn't work either. So, I'd like to know if there's a way of dynamically adding multiple URLs to different sections of the same text which will link to web content? Thank you, Martyn

    Read the article

  • Regex - Modifying strings except in specified enclosures - PHP

    - by Kovo
    I have found similar answers to my current needs on SO, however I am still trying to grasp modifying strings based on a rule, except in certain enclosures within those strings. Example of what Im trying to accomplish now: preg_replace("/\s*,\s*/", ",", $text) I found the above in many places. It will remove spaces before and after all commas in a string. That works great. However, if I want to exclude modifying commas found within " ", I am not sure how that rule has to be modified. Any help? Thanks! EDIT: I want to clarify my question: I would like all whitespace before and after the commas in the following sentence removed, except commas found in double or single quotes: a, b , c "d, e f g , " , h i j ,k lm,nop Expected result: a,b,c "d, e f g , ",h i j,k lm,nop

    Read the article

  • C++: set of C-strings

    - by Nicholas
    I want to create one so that I could check whether a certain word is in the set using set::find However, C-strings are pointers, so the set would compare them by the pointer values by default. To function correctly, it would have to dereference them and compare the strings. I could just pass the constructor a pointer to the strcmp() function as a comparator, but this is not exactly how I want it to work. The word I might want to check could be part of a longer string, and I don't want to create a new string due to performance concerns. If there weren't for the set, I would use strncmp(a1, a2, 3) to check the first 3 letters. In fact, 3 is probably the longest it could go, so I'm fine with having the third argument constant. Is there a way to construct a set that would compare its elements by calling strncmp()? Code samples would be greatly appreciated.

    Read the article

  • Rails: Internationalization of Javascript Strings?

    - by Matt Rogish
    So, we have an existing Rails 2.3.5 app that does not support Internationalization at all. Now, I'm well familiar with Rails I8n stuff, but we have a LOT of output strings inside /javascripts/. I'm not a huge fan of this approach, but unfortunately it is too late to fix it now. How might we internationalize strings stored in JS files in a Rails app? Rails doesn't even serve the JS files... I'm thinking I could always have the Rails app serve up the JS files, but that seems pretty gross. Are there plugins to do this? Yikes.

    Read the article

  • concatenating strings from two different rows in a table

    - by Azeem
    Hello, We are attempting to rework the SQL in a product. The product stores XML in a table as follows: XML_STORAGE - UID IDENTITY - PARENT_ID INTEGER - SEQ INTEGER - XML VARCHAR(3800) The current way of doing this is as follows: Retrieve all ROWS for PARENT_ID = n. Then go over the fetched rows in the code and concatenate the XML strings into one large XML before parsing. The SEQ column is used to ORDER the result so the XML strings can be concatenated properly. Hopefully that is clear. What we are attempting to do is rework this so we can use a SQL variant to retrieve the whole string and just fetch one row back from DB2. Is there a DB2 function that will allow us to concatenate the string in all of these rows into one large string in the resultset. How would such a SQL look. Please let me know. Any help is much appreciated. Thanks! - Azeem

    Read the article

  • Collaborative localization website supporting Android strings.xml?

    - by Nicolas Raoul
    My open source Android application has internationalization done the Android way, with strings.xml files. The community has many people from many countries, and they are willing to contribute/improve translations using a collaborative website. There is Launchpad but it only supports the gettext format so we would have to use scripts, not very convenient. There is Crowdin but somehow this website seems dead, nearly no projects, and the download links do not work. Actually we started using Crowdin but all download links fail to give any strings.xml file back, see here. What website is convenient for translating open source Android applications?

    Read the article

  • comparing strings in PostgreSQL

    - by binaryLV
    Hello! Is there any way in PostgreSQL to convert UTF-8 characters to "similar" ASCII characters? String glažškunu rukiši would have to be converted to glazskunu rukisi. UTF-8 text is not in some specific language, it might be in Latvian, Russian, English, Italian or any other language. This is needed for using in where clause, so it might be just "comparing strings" rather than "converting strings". I tried using convert, but it does not give desired results (e.g., select convert('A', 'utf8', 'sql_ascii') gives \304\200, not A). Database is created with: ENCODING = 'UTF8' LC_COLLATE = 'Latvian_Latvia.1257' LC_CTYPE = 'Latvian_Latvia.1257' These params may be changed, if necessary.

    Read the article

  • Working with strings in C++

    - by Elliot Bonneville
    Hi. I'm working with strings in C++. I recently came across a problem when entering strings. I'm using cin >> string; to get my string as user input. When the user enters a space into the string, the next input is automatically filled out with the remaining letters, or sometimes left blank. As the next input string is often an integer, this will result in an unpleasant bug. What's a good fix for this?

    Read the article

  • Attributed strings in UITableViewCells without WebView?

    - by arnekolja
    Hello, does anyone know if there's a way in with 3.0+ to display attributed strings within a UITableViewCell without using a UIWebView for that? I need to display a string with linked, tappable substrings as the typical detailTextLabel. I wouldn't mind exchanging this UILabel against another type of view, but I think a UIWebView could be just too slow when rendering a table with hundrets of cells. Or does someone have opposite experiences here? So my question is: what's the best way to achieve mixed strings in a very large table without a great performance hit? I searched for this almost a whole day now, but I can only find old posts mentioning that there's no attributed string on the iPhone (outdated, as this was pre-3.0) and/or saying that they use a UIWebView for that. But really, I don't think this would perform very well on large tables, would it? Many, many thanks in advance Arne

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >