[Solved] python, count characters in last line string [closed]

Split the string from the end(str.rsplit) only once and get the length of last item: >>> s = “””AAAAAAA BBBB CCCCC DDD””” >>> s.rsplit(‘\n’, 1) [‘AAAAAAA\n BBBB\n CCCCC’, ‘ DDD’] #On the other hand simple str.split will split the string more than once: >>> s.split(‘\n’) [‘AAAAAAA’, ‘ BBBB’, ‘ CCCCC’, ‘ DDD’] Now simply get … Read more

[Solved] how to add strings together?

You have several issues here: First of all, your string cu is declared inside the if scope. It will not exist outside that scope. If you need to use it outside the scope of the if, declare it outside. Second, math operations cannot be applied to strings. Why are you casting your numeric values to … Read more

[Solved] Get unreadable string from GPS tracker

Its really some binary information and If you have clearly read out the product manual then it says formation of this binaries. Converting the data to hex will give something like this.. 24-41-20-20-67-72-51-30-35-41-68-40-91-29-3F-3F-3F-FF-FF-FB-FF-FF-3F-3F- And then you need to refer the manual for exact meaning of these hex numbers ex–(in some chinese devices) 2 bytes(24), stand … Read more

[Solved] My basic cipher based encryption method in C++ is not working properly, how can I fix it? [closed]

I suggest placing all your valid characters into a string, then using the % operator. const std::string valid_characters = “abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*”; const unsigned int shift_offset = 13; std::string::size_type position = valid_characters.find(incoming_character); position = (position + shift_offset) % valid_characters.length(); char result = valid_characters[position]; You will have to check the position value because find will return std::string::npos if … Read more

[Solved] How to split strings based on “/n” in Java [closed]

Don’t split, search your String for key value pairs: \$(?<key>[^=]++)=\{(?<value>[^}]++)\} For example: final Pattern pattern = Pattern.compile(“\\$(?<key>[^=]++)=\\{(?<value>[^}]++)\\}”); final String input = “$key1={331015EA261D38A7}\n$key2={9145A98BA37617DE}\n$key3={EF745F23AA67243D}”; final Matcher matcher = pattern.matcher(input); final Map<String, String> parse = new HashMap<>(); while (matcher.find()) { parse.put(matcher.group(“key”), matcher.group(“value”)); } //print values parse.forEach((k, v) -> System.out.printf(“Key ‘%s’ has value ‘%s’%n”, k, v)); Output: Key ‘key1’ … Read more

[Solved] regex to find variables surrounded by % in a string

I believe you are looking for a regex pattern (?<!%%)(?<=%)\w+(?=%)(?!%%) That would find variables that are surrounded by a single % character on each side. Test the regex here. Java code: final Pattern pattern = Pattern.compile(“(?<!%%)(?<=%)\\w+(?=%)(?!%%)”); final Matcher matcher = pattern.matcher(input); while (matcher.find()) { System.out.println(matcher.group(0)); } Test the Java code here. UPDATE: If you want … Read more

[Solved] Java String.split() without specific symbol [closed]

You can do that with split() and some regex-magic: System.out.println( Arrays.toString( “3332255766122”.split( “(?<=(.))(?!\\1)” ) )); Output: [333, 22, 55, 7, 66, 1, 22] Regex breakdown: (?<=x) is a positive zero-width look-behind, so it will match the position right after the match for subexpression x (.) as epxression for x above is a capturing group that … Read more

[Solved] Printing characters from a string occurring in another string [closed]

You can use the code similar to this which gives the required output public class ProgramOnStrings { public static void main(String[] args) { // TODO Auto-generated method stub Compare cobj=new Compare(); cobj.compareStrings(); } } class Compare { String s1=”helloworld”; String s2=”hord”; int array[]; String small,big; Compare() { if(s1.length()<s2.length()) { small=s1; big=s2; array=new int[small.length()]; } else … Read more

[Solved] How to represent unsigned char values as hexadecimal string?

I want to get a return values 3374747372 as char or string. Casting doesn’t work in this case. You can use text formatting IO to get a hex string representation of the arrays content: unsigned char codeslink[5] ={ 0x33, 0x74, 0x74, 0x73, 0x72}; std::ostringstream oss; oss << std::hex << std::setfill(‘0’); for(size_t i = 0; i … Read more

[Solved] Perl : Get array of all possible cases of a string

If you’re aiming to use if for glob anyway then you can use glob‘s built-in pattern generation my $filename=”File.CSV”; my $test = $filename =~ s/([a-z])/sprintf ‘{%s,%s}’, uc($1), lc($1)/iegr; say $test, “\n”; say for glob $test; output {F,f}{I,i}{L,l}{E,e}.{C,c}{S,s}{V,v} FILE.CSV FILE.CSv FILE.CsV FILE.Csv FILE.cSV FILE.cSv FILE.csV FILE.csv FILe.CSV FILe.CSv FILe.CsV FILe.Csv FILe.cSV FILe.cSv FILe.csV FILe.csv FIlE.CSV FIlE.CSv … Read more

[Solved] How to change direction in snake game [closed]

Your question is “how to fix this code”, not “give me the right code”. I will not give you the right code. I will answer the original question. The answer to that question is this: The problem is that you do cout << “***”. This will alwys draw three asterisks horizontally. That command will never … Read more

[Solved] conditionally concatenate text from multiple records in vba [duplicate]

Try the below code, it assumes you have headers and that unique ID is in column A and description in column B. Option Explicit Sub HTH() Dim vData As Variant Dim lLoop As Long Dim strID As String, strDesc As String ‘// Original data sheet, change codename to suit vData = Sheet1.UsedRange.Value With CreateObject(“Scripting.Dictionary”) .CompareMode … Read more

[Solved] how to separate a number from a string [closed]

I don’t see your problem with strtok, it would be perfect in this case I think. In pseudo-code: line = getline(); split_line_into_tokens(line); if tokens[0] == “command1” { if tokens_num > 2 { error(“to many arguments to command1”); } else if tokens_num < 2 { error(“command1 needs one argument”); } else { do_command_1(tokens[1]); } } else … Read more