Search Results

Search found 44874 results on 1795 pages for 'string format'.

Page 32/1795 | < Previous Page | 28 29 30 31 32 33 34 35 36 37 38 39  | Next Page >

  • when to use StringBuilder in java

    - by kostja
    It is supposed to be generally preferable to use a StringBuilder for String concatenation in Java. Is it always the case? What i mean is : Is the overhead of creating a StringBuilder object, calling the append() method and finally toString() smaller then concatenating existing Strings with + for 2 Strings already or is it only advisable for more Strings? If there is such a threshold, what does it depend on (the String length i suppose, but in which way)? And finally - would you trade the readability and conciseness of the + concatenation for the performance of the StringBuilder in smaller cases like 2, 3, 4 Strings?

    Read the article

  • PHP Extract Values From One String Based on a Pattern Defined in Another

    - by ironkeith
    I have two strings: $first = '/this/is/a/string'; $second = '/this/:param1/a/:param2'; And I'm trying to get this: $params = array('param1' => 'is', 'param2' => 'string'); But getting from point a to b is proving more than my tired brain can handle at the moment. Anything starting with a ':' in the second string defines a variable name/position. There can be any number of variables in $second which need to be extracted from $first. Segments are separated by a '/'. Thanks.

    Read the article

  • Convert String containing several numbers into integers

    - by GobiasKoffi
    I realize that this question may have been asked several times in the past, but I am going to continue regardless. I have a program that is going to get a string of numbers from keyboard input. The numbers will always be in the form "66 33 9" Essentially, every number is separated with a space, and the user input will always contain a different amount of numbers. I'm aware that using 'sscanf' would work if the amount of numbers in every user-entered string was constant, but this is not the case for me. Also, because I'm new to C++, I'd prefer dealing with 'string' variables rather than arrays of chars.

    Read the article

  • Python sort 2-D list by time string

    - by Mark Kennedy
    How do I sort a multi dimensional list like this based on a time string? The sublists can be of different sizes (i.e. 4 and 5, here) I want to sort by comparing the first time string in each sublist (sublist[-4]) x = (['1513', '08:19PM', '10:21PM', 1, 4], ['1290', '09:45PM', '11:43PM', 1, 4], ['0690', '07:25AM', '09:19AM', 1, 4], ['0201', '08:50AM', '10:50AM', 1, 4], ['1166', '04:35PM', '06:36PM', 1, 4], ['0845', '05:40PM', '07:44PM', 1, 4], ['1267', '07:05PM', '09:07PM', 1, 4], ['1513', '08:19PM', '10:21PM', 1, 4], ['1290', '09:45PM', '11:43PM', 1, 4], ['8772', '0159', '12:33PM', '02:43PM', 1, 5], ['0888', '0570', '09:42PM', '12:20AM', 1, 5], ['2086', '2231', '04:10PM', '06:20PM', 1, 5]) The sorted result would be sortedX = (['0690', '07:25AM', '09:19AM', 1, 4], ['0201', '08:50AM', '10:50AM', 1, 4], ['1166', '04:35PM', '06:36PM', 1, 4], ['0845', '05:40PM', '07:44PM', 1, 4], ['1267', '07:05PM', '09:07PM', 1, 4], ['1513', '08:19PM', '10:21PM', 1, 4], ['1513', '08:19PM', '10:21PM', 1, 4], ['1290', '09:45PM', '11:43PM', 1, 4], ['1290', '09:45PM', '11:43PM', 1, 4], ['8772', '0159', '12:33PM', '02:43PM', 1, 5], ['2086', '2231', '04:10PM', '06:20PM', 1, 5], ['0888', '0570', '09:42PM', '12:20AM', 1, 5]) I tried the following: sortedX = sorted(x, key=lambda k : k[-4]) #k[-4] is the first time string and it works but it doesn't respect the sublist size ordering

    Read the article

  • c# marshaling dynamic-length string

    - by mitsky
    i have a struct with dynamic length [StructLayout(LayoutKind.Sequential, Pack = 1)] struct PktAck { public Int32 code; [MarshalAs(UnmanagedType.LPStr)] public string text; } when i'm converting bytes[] to struct by: GCHandle handle = GCHandle.Alloc(value, GCHandleType.Pinned); stru = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T)); handle.Free(); i have a error, because size of struct less than size of bytes[] and "string text" is pointer to string... how can i use dynamic strings? or i can use only this: [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]

    Read the article

  • Pick Random String From Array

    - by atrljoe
    How do I go about picking a random string from my array but not picking the same one twice. string[] names = { "image1.png", "image2.png", "image3.png", "image4.png", "image5.png" }; Is this possible? I was thinking about using return strings[random.Next(strings.Length)]; But this has the possibility of returning the same string twice. Or am I wrong about this? Should I be using something else like a List to accomplish this. Any feedback is welcome.

    Read the article

  • How to create an formatted localized string?

    - by mystify
    I have an localized string which needs to take a few variables. However, in localization it is important that the order of the variables can change from language to language. So this is not a good idea: NSString *text = NSLocalizedString(@"My birthday is at %@ %@ in %@", nil); In some languages some words come before others, while in others it's reverse. I lack of an good example for the moment. How would I provide NAMED variables in an formatted string? Is there any way to do it without some heavy self-made string replacements? Even some numbered variables like {%@1}, {%@2}, and so on would be sufficient... is there a solution?

    Read the article

  • How to assign HTML value to a asp.net string variable

    - by Zerotoinfinite
    I am using asp.net and C#. I want to send mail to my user in HTML format, I have the content in HTML format let say like this <table style="width:100%;"> <tr> <td style="width:20%; background-color:Blue;"></td> <td style="width:80%; background-color:Green;"></td> </tr> </table> Now I am unable to assign this to a string variable, so that I could send it as a mail. Please let me know how can I bind this whole HTML content into a varibale. Also, please note that the above code is only a demo, I have around 100 lines of HTML code.

    Read the article

  • Comparing Each Character in Java String

    - by user2760357
    I am a beginner at java, and I am trying to create two strings and compare each character. If there is a matching character or characters, the code has to print out the length of each string, without the matching characters. For example, if one string is "super," and the other is "perfect," the program should interpret the strings as superfect, and print out 9 However, if there is no matching part, like pencil and eraser, the code should printout 12, which is the length of two strings combined. Right now, I am having a problem with comparing each character, since I tried to use if(input_word.compareToIgnoreCase(input_word2) != 0) but it only compared the string as a whole.. any suggestion? Thank you for your efforts

    Read the article

  • What is the correct connection string for SQL 2000 server in entity framework

    - by M-Askman
    I success to use entity framework for MySQL but reverse code can not be used with SQL Server 2000, then i guess to change connection string to connect SQL Server 2000, however, got error <add name="BetterContext" connectionString="Data Source=server2;Initial Catalog=GoodDB;User ID=sa;Password=hello;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" /> An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct public partial class BetterContext : DbContext { static BetterContext() { Database.SetInitializer<BetterContext>(null); } public livefeedContext() : base("Name=BetterContext") { }

    Read the article

  • Android Loading & Playing Sound Based on String

    - by Chance
    I'm currently working on a simple Android app, and right now I am trying to get it to load in and play sounds. The problem I am faced with is that I want the sound it uses to be based on a string (With the same name as the sound file). The reason for this is simplicity in both the code and adding on to it. Now unfortunately I can't just slap a string in place of referencing the actual sound, but is there some way for me to compare a string to the entire raw folder to find the matching sound, or some other alternative short of defining every sound manually? Thank you for your time.

    Read the article

  • String as \x03\x00\x00\x00 to integer

    - by marta
    Helo: I have a question, that I solved in c, but now I want to do it in hava: I have a String like: '\x03\x00\x00\x00' This is representing an hexadecimal value of a integer. I transform to 0x03\0x00... And now I want to obtain the integer, but I don't know how to do it in java could someone give me some idea ? Thanks in advance (Is it some way to use this format ('\x03\x00\x00\x00' ) directly without use byte[] arrays? and in C can I use this format directly to build a integer (int)?)

    Read the article

  • Convert unusual string into date time

    - by BlueChippy
    I have a system that outputs dates in the format "1{yy}{MM}{dd}" and I am trying to find a good way to parse it back into a real date. At the moment I am using this: var value = "1110825"; var z = Enumerable.Range(1,3).Select(i => int.Parse(value.Substring(i, 2))).ToList(); var d = new DateTime(2000 + z[0], z[1], z[2]); but I'm sure there's a cleaner/more efficient way to do it? I've tried DT.ParseExact, but can't find a suitable format string to use.

    Read the article

  • using different string files in android

    - by boreas
    I'm porting my iPhone app to android and I'm having a problem with the string files now. The app is a translation tool and users can switch the languages, so all the localized strings are in both languages and they are independent from what locale the OS is running. For iOS version I have different files like de.strings, en.strings and fr.strings and so on. For every target with specified language pair I read the strings from the string tables, e.g. for de-fr I will include de.strings and fr.strings in project and set the name of the string tables in the info-list file and read strings from them. In the end I have one project containing different targets (with different info-list files) and all are well configured. I'm intending to do the same on android platform, but Is only one strings.xml allowed per project? How do I set different build target? How do I specify per target which strings.xml it should read?

    Read the article

  • Using an int as the numerical representation of a string in C#

    - by bluewall21
    I'm trying to use an integer as the numerical representation of a string, for example, storing "ABCD" as 0x41424344. However, when it comes to output, I've got to convert the integer back into 4 ASCII characters. Right now, I'm using bit shifts and masking, as follows: int value = 0x41424344; string s = new string ( new char [] { (char)(value >> 24), (char)(value >> 16 & 0xFF), (char)(value >> 8 & 0xFF), (char)(value & 0xFF) }); Is there a cleaner way to do this? I've tried various casts, but the compiler, as expected, complained about it.

    Read the article

  • Accessing object's method within string

    - by Wild One
    Recently I was reading php documentation and found interesting note in string section: Functions, method calls, static class variables, and class constants inside {$} work since PHP 5. However, the value accessed will be interpreted as the name of a variable in the scope in which the string is defined. Using single curly braces ({}) will not work for accessing the return values of functions or methods or the values of class constants or static class variables. See www.php.net/manual/en/language.types.string.php It says, that I can't use curly syntax to get value returned by object's method call. Is it a mistake in manual or I misunderstood it, because I tried the following code and it works just fine: <?php class HelloWorld { public static function hello() { echo 'hello'; } } $a = new HelloWorld(); echo "{$a->hello()} world";

    Read the article

  • Function to get a string and return same after processing in C

    - by C0de_Hard
    I am working on a code which requires a function. This function gets a string as input and returns a string. What I have planned so far is to get a str[], remove all $'s and spaces, and store this in another string which is returned later: char *getstring(char str[]) { int i=0; char rtn[255]; while (i<strlen(str)) { if (str[i] != " " || str[i] != "$" ) rtn[i] = str[i]; else rtn[i] = ''; } return str; } I dont feel like this will work. Any ideas?? :-S

    Read the article

  • .NET string replace russian to english

    - by Fabio Beoni
    I have a strange problem replacing chars in string... I read a .txt file containing russian text, and starting from a list of letters russian to english (ru=en), I loop the list and I WOULD like to replace russian characters with english characters. The problem is: I can see in the debug the right reading of the russian and the right reading of the english, but using myWord = myWord.Replace(ruChar, enChar), the string is not replaced. My txt file is a UTF-8 encoding.

    Read the article

< Previous Page | 28 29 30 31 32 33 34 35 36 37 38 39  | Next Page >