string-formatting

Formatting a simple string, but `java.lang.NoSuchMethodError`

好久不见. 提交于 2019-12-05 05:07:24
I'm using Scala 2.9.2. Run Scala and test a simple code, this code is… OK: ... val title = "Hashing file (%s)..." format sizeToStr(file.length) But I couldn't understand what is what, while I put that code into a simple app, compiling OK, at runtime it throws this one: java.lang.NoSuchMethodError: scala.Predef$.augmentString(Ljava/lang/String;)Lscala/collection/immutable/StringOps; at group.pals.penguin.app.shasher.Shasher$.calcHash(shasher.scala:119) at group.pals.penguin.app.shasher.Shasher$.main(shasher.scala:76) at group.pals.penguin.app.shasher.Shasher.main(shasher.scala) at sun.reflect

Formatting columns containing non-ascii characters

白昼怎懂夜的黑 提交于 2019-12-05 04:14:23
So I want to align fields containing non-ascii characters. The following does not seem to work: for word1, word2 in [['hello', 'world'], ['こんにちは', '世界']]: print "{:<20} {:<20}".format(word1, word2) hello world こんにちは 世界 Is there a solution? You are formatting a multi-byte encoded string. You appear to be using UTF-8 to encode your text and that encoding uses multiple bytes per codepoint (between 1 and 4 depending on the specific character). Formatting a string counts bytes , not codepoints, which is one reason why your strings end up misaligned: >>> len('hello') 5 >>> len('こんにちは') 15 >>> len(u

How can I escape '%' character in a gettext string?

微笑、不失礼 提交于 2019-12-05 03:12:30
I use gettext to translate my user interface. I'd like to write symbol % as part of a UI caption in a string, but since it has a special meaning, does not works as expected. How can I escape percent symbols? Use %% to escape %. 来源: https://stackoverflow.com/questions/3728272/how-can-i-escape-character-in-a-gettext-string

Fastest way to insert these dashes in python string?

夙愿已清 提交于 2019-12-05 02:15:31
So I know Python strings are immutable, but I have a string: c['date'] = "20110104" Which I would like to convert to c['date'] = "2011-01-04" My code: c['date'] = c['date'][0:4] + "-" + c['date'][4:6] + "-" + c['date'][6:] Seems a bit convoluted, no? Would it be best to save it as a separate variable and then do the same? Or would there basically be no difference? You could use .join() to clean it up a little bit: d = c['date'] '-'.join([d[:4], d[4:6], d[6:]]) You are better off using string formatting than string concatenation c['date'] = '{}-{}-{}'.format(c['date'][0:4], c['date'][4:6], c[

UnknownFormatConversionException is caused by symbol '%' in String.format()

◇◆丶佛笑我妖孽 提交于 2019-12-05 00:26:48
String template = "%s and '%'"; String result = String.format(template, "my string"); System.out.println(result); Expected : my string and '%' But result is : java.util.UnknownFormatConversionException: Conversion = ''' Why? How to correctly declared the sequence '%' so that it's ignored by String.format() ? % is already used by format specifiers so it requires an additional % to display that character: String template = "%s and '%%'"; 来源: https://stackoverflow.com/questions/16713396/unknownformatconversionexception-is-caused-by-symbol-in-string-format

.NET GUID uppercase string format

前提是你 提交于 2019-12-05 00:19:19
I need to format my GUIDs in the dashed format, all uppercase. I know using myGuid.ToString("D") or String.Format("{0:D}", myGuid) gives the dashed format, but using an uppercase D as opposed to a lower-case d doesn't give me an uppercased GUID like I thought it would. Is there a way to do this without doing anything crazy, or do I just need to call myGuid.ToString().ToUpper() ? do I just need to call myGuid.ToString().ToUpper() Yep. You could go to the effort of creating a custom IFormatProvider, but it doesn't seem worth it here. Note that RFC 4122 , which defines the UUID specification,

Calling ToString(“YYYY-mm-dd”) results in wrong date format

断了今生、忘了曾经 提交于 2019-12-04 23:54:40
I've got a constructor which takes a DateTime object: public Report(DateTime date, string start = "0", string end = "0") { Logger.Info("Creating a new Report..."); StartTime = start; EndTime = end; Date = date.ToString("YYYY-mm-dd"); SetStartEndTimes(); Logger.Info("Report Created"); } Now, this was working fine just 3 days ago. However, I come back today, after a break, and this is the results I'm seeing: As you can see, the date being passed in is right. However, after the format, it is not. Again, this worked before my break. I come back, and I get this. Am I missing something? Why would it

Remove all occurrences of several chars from a string

╄→尐↘猪︶ㄣ 提交于 2019-12-04 23:05:13
Is there a pythonic way to do what the str.strip() method does, except for all occurrences, not just those at the beginning and end of a string? Example: >> '::2012-05-14 18:10:20.856000::'.strip(' -.:') >> '2012-05-14 18:10:20.856000' I want >> '::2012-05-14 18:10:20.856000::'.crazy_function(' -.:') >> '20120514181020856000' Does Python provides me a built-in crazy_function ??? I could easily do it programatically, but I want to know if there is a built-in for that. Couldn't find one. Thank you for your help. Use the translate function to delete the unwanted characters: >>> '::2012-05-14 18

C# String.Format with Curly Bracket in string [duplicate]

让人想犯罪 __ 提交于 2019-12-04 22:27:21
Possible Duplicate: Escape curly brace '{' in String.Format c# has a String.Format method that allows you to format a string but inserting params with the tokens {0} {1} I am trying to create a simple json string which requires curly brackets to be in the string, and so it is breaking the formatter String.Format("{ foo:'{0}', bar:'{1}' }", foo, bar); Adding an escape before the braces did not help Throws a exception saying my string is incorrectly formatted, anyone know how to get around this? You can escape the braces by doubling them up in your format strings: string.Format("{{ foo: '{0}',

iOS APNS: sending the device token to the provider in string format

送分小仙女□ 提交于 2019-12-04 20:34:33
问题 I need to send the APNS device token of my iOS app to my provider by calling a service that expects JSON data in my request. I'm reading Apple's Local and Push Notification Programming Guide and it only says that the application:didRegisterForRemoteNotificationsWithDeviceToken: delegate method passes the device token as NSData and you should pass it to your provider encoded in binary data. But I need it to be converted to string in order to be able to send a JSON request to my provider. I've