Posts

Showing posts with the label string

Add null-like value to String in Java

Image
Clash Royale CLAN TAG #URR8PPP Add null-like value to String in Java I am writing test method like setTask(Task task) . And Task object has several fields, e.g. setTask(Task task) Task public String vehicle; Method setTask should be used in different test-cases, so I'd like to have an options for this field to accept values: setTask null some string value "", "Hello, World!", "Iso Isetta", ... random So what can I do to make String to be SpecialString which could accept values null , random & some string value ? (BTW: I don't want to set it to string value "RANDOM", and chech whether the value is equal to "RANDOM"-string) String SpecialString null random some string value UPDATE: I don't mean random like random value from a set of values , I mean random as well as null and this is for setTask() to handle random (select random from drop-down), and not to pass a random string from a set of values. random random ...

How to split string into substrings of identical letters?

Image
Clash Royale CLAN TAG #URR8PPP How to split string into substrings of identical letters? How do I split a string consisting of lowercase English alphabetical letters into substrings consisting of identical letters - so for an input : "aaaabbcccdd" The function should output a list: ["aaaa", "bb", "ccc", "dd"] checkout itertools.groupby – Chris_Rands 1 hour ago itertools.groupby Should é and e be classed as identical? What have you tried? – Sayse 51 mins ago The string consists of only English alphabetical characters. I'll amend the post. – Uke...

Android plurals not working properly when you change system language

Image
Clash Royale CLAN TAG #URR8PPP Android plurals not working properly when you change system language My application has only polish strings, it's default language of an app. Here you can see example plurals placed under res/vaules: <plurals name="number_of_vouchers"> <item quantity="one">%d kupon</item> <item quantity="few">%d kupony</item> <item quantity="many">%d kuponów</item> <item quantity="other">%d kuponów</item> </plurals> Here you have test activity class: class DevTest : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_dev_test) val stb = StringBuilder() for (j in 1..30) { stb.append(resources.getQuantityString(R.plurals.number_of_vouchers, j, j) + "n") } testTV.text = stb.toString() } } This how example test looks ...

Strings are objects in Java, so why don't we use 'new' to create them?

Image
Clash Royale CLAN TAG #URR8PPP Strings are objects in Java, so why don't we use 'new' to create them? We normally create objects using the new keyword, like: new Object obj = new Object(); Strings are objects, yet we do not use new to create them: new String str = "Hello World"; Why is this? Can I make a String with new ? new You should also have a look on this question stackoverflow.com/questions/456575/java-wrapper-equality-test – changed Jan 5 '10 at 21:56 Because string literals are already objects. – EJP Feb 7 '16 at 9:33 Note that new String(...) has been used to circumvent an implementation detail when substringing large string...

Remove specific characters from a string in Python

Image
Clash Royale CLAN TAG #URR8PPP Remove specific characters from a string in Python I'm trying to remove specific characters from a string using Python. This is the code I'm using right now. Unfortunately it appears to do nothing to the string. for char in line: if char in " ?.!/;:": line.replace(char,'') How do I do this properly? It's been over 5 years, but how about using the filter function and a Lambda Expression: filter(lambda ch: ch not in " ?.!/;:", line) . Pretty concise and efficient too, I think. Of course, it returns a new string that you'll have to assign a name to. – John Red Feb 6 '16 at 10:35 filter filter(lambda ch: ch not in " ?.!/;:", line) @JohnRed: Actually it returns an iterator that returns a list of characters but if you...

How do I use != in java strings [closed]

Image
Clash Royale CLAN TAG #URR8PPP How do I use != in java strings [closed] My code has a validator which states that if "d" is entered display an error message. If "c", "s", or "v" are entered do the calculation. How can I construct gender.equalsIgonreCase to include all words and letters that are not "c", "s", or "v"? gender.equalsIgonreCase Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question. All ASCII letters but c , s , v ? gender.matches("(?i)[a-z&&[^csv]]") ? – Wiktor Stribiżew Sep 22 '16 at 21:18 ...

Using regex to split list of strings into list of lists based on starting character

Image
Clash Royale CLAN TAG #URR8PPP Using regex to split list of strings into list of lists based on starting character I have a very long list of 9000+ elements. For example Sample is below: lst = ['0sbsd uu', '7fsfss us', 'Bsfsd ll', 'Zufss dl', 'fasfs ff', '8fsdr2 us', 'It fss', 'Fsffsfds f'] I have to split lst into a list of 15 "almost" equal size sublists such that each sublist contains all the entries starting with a given character range (say 0 - c, d - h, .... ). lst 0 - c, d - h, .... By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

How to open a file handle on a string in Perl 6?

Image
Clash Royale CLAN TAG #URR8PPP How to open a file handle on a string in Perl 6? In Perl 5, I can open a filehandle on string like this: open my $kfh, "<", $message->payload; I have a scenario that uses string as a filehandle and passes it to the open method: open my $fh = new IO::Zlib; open my $kfh, "<", $message->payload; if($fh->open($kfh, 'rb')){ print <$fh>; $fh->close; } where $message->payload is read from Kafka, and the content is a byte array. raiph had a similar question, but it didn't answer my question. $message->payload So I want to know how to open a filehandle on a string in Perl 6 like Perl 5 does? These documentation pages have no information on this: The documentation has a section about this under Input/Output. – callyalater Jul 18 at 17:22 ...