[Solved] Replacing part of string python [closed]

For the simplest case, you might solve this with a regular expression: >>> import re >>> re.sub(r”(‘?null’?)”, “‘Null'”, “{‘abcd’: null}”) “{‘abcd’: ‘Null’}” >>> re.sub(r”(‘?null’?)”, “‘Null'”, “{‘abcd’: ‘null’}”) “{‘abcd’: ‘Null’}” >>> but from the look of you example and the comment (which should really be part of your question) mentionning you might have a lot more … Read more

[Solved] String not returned [closed]

Your String result = “”; is null check it Your are returning null string change it You should return sb.toString(); instead of return result; EDIT public class PreDefinedAttributes { private Context mContext; private String mobile_os, mobile_model, mobile_brand, mobile_version, mobile_manufacturer; private String sdk_version, src, appname, appversion; private String lat = “”, lng = “”, device_id; private … Read more

[Solved] Java Quoting string variables

You start by taking the string. ansible-playbook delete.yml –extra-vars “host=5.955.595 user=root pass=anotherpw vm=myVm” Then you escape all special characters. In this case, that’s just the 2 double-quotes. ansible-playbook delete.yml –extra-vars \”host=5.955.595 user=root pass=anotherpw vm=myVm\” Then you surround that with double-quotes, to make it a Java string literal. “ansible-playbook delete.yml –extra-vars \”host=5.955.595 user=root pass=anotherpw vm=myVm\”” Then … Read more

[Solved] Distance between two alphabets in a string

You can just use the str.index(char, [beg, end]) method to retrieve the position of a character inside a string. The method allows you to add a beginning and end position that you can use to check for the different occurrences. Here the code: s=”CNCCN” dist = s.index(‘N’, s.index(‘N’) + 1) – s.index(‘N’) And its output: … Read more

[Solved] How to extract a string between two of the SAME delimiters T-SQL?

Use CHAR_INDEX twice: SELECT *, SUBSTRING(path, pos1 + 1, pos2 – pos1 – 1) FROM tests CROSS APPLY (SELECT NULLIF(CHARINDEX(‘\’, path), 0)) AS ca1(pos1) CROSS APPLY (SELECT NULLIF(CHARINDEX(‘\’, path, pos1 + 1), 0)) AS ca2(pos2) — NULLIF is used to convert 0 value (character not found) to NULL Test on db<>fiddle 1 solved How to … Read more

[Solved] Why to use compare() for strings?

The idea that “some compilers don’t work properly” is absurd. If you’re comparing C-style strings via char* pointers, then the =, !=, <=, … operators compare the pointers, not the strings they point to. In that case, use the strcmp() function instead. But since you’re asking about the compare function, you’re clearly not asking about … Read more

[Solved] Cutting ‘ \0’ from strings [closed]

Your problem is evident in your debug output. getline does not strip the newline from the input, so for example you are searching for: “know\n” in “I do not know what to write\n” So your problem is not about stripping the \0 string terminator, but rather stripping the \n line-end. That can be achieved in … Read more

[Solved] String.indexOf gives a value one less than expected

Indexes are zero-based: ↓ Peter Piper picked a peck of pickled pepper 111111111122222222223333333333444 0123456789012345678901234567890123456789012 ↑ The first p is at index 8. From the javadoc of indexOf(): Returns the index of the first occurrence of the character in the character sequence represented by this object, or -1 if the character does not occur. solved String.indexOf … Read more