[Solved] Changing vector in function by pointer

The function does not make sense. For starters it is unclear why you are using a pointer to the vector instead of a reference to the vector. Nevertheles, this declaration vector<unsigned char> vec(5); does not reseeve a memory for the vector. It initializes the vector with 5 zero-characters which will be appended with other characters … Read more

[Solved] How can I solve this String length problem?

Have you tried calculating the length within the function rather than in the console log? This ensures that all of the logic is first completed within the function before it is returned in the console log. Your function expects the string name, but you are passing name.length function getNameLength(name){ return name.length; } console.log(getNameLength(‘John’)); console.log(getNameLength(‘Argentina!’)); console.log(getNameLength(‘Macedonia’)); … Read more

[Solved] What does char a[50][50] mean in C?

char a[50][50] declares a as a 50-element array of 50-element arrays of char. That means each a[i] is a 50-element array of char. It will be laid out in memory like: +—+ a: | | a[0][0] +—+ | | a[0][1] +—+ | | a[0][2] +—+ … +—+ | | a[0][49] +—+ | | a[1][0] +—+ … Read more

[Solved] Jquery – Find a word in a string and wrap it with tag

You need to do this : var txt = textDiv.replace(new RegExp(searchInput, ‘gi’), function(str) { return “<span class=”highlight”>” + str + “</span>” }); or var txt = textDiv.replace( new RegExp(searchInput, ‘gi’), “<span class=”highlight”>$&</span>”); gi -> all case insensitive matching text $(document).ready(function() { // globals var searchInput; var textDiv; $(‘.searchBtn’).click(function(event) { event.preventDefault(); // set the values of … Read more

[Solved] Output accumulates each iteration instead of resetting [closed]

You’re reusing the same string buffer. If you keep putting things into the same buffer without clearing it, you’re obviously going to get extraneous stuff from previous iterations. Simply declare the StringBuffer inside the while loop so that it is created on each iteration. Anyway, you should learn to use your debugger, instead of asking … Read more

[Solved] return the list with strings with single occurrence [closed]

Something like this… List<String> result = Stream.of(“A”, “A”, “BB”, “C”, “BB”, “D”) .collect(Collectors.groupingBy( Function.identity(), Collectors.counting())) .entrySet() .stream() .filter(x -> x.getValue() == 1L) .map(Entry::getKey).collect(Collectors.toList()); System.out.println(result); // [C, D] 2 solved return the list with strings with single occurrence [closed]

[Solved] Working with strings in java : extract a particular string [closed]

First make ‘path’ a StringBuffer to make it easier to work with. Then use indexes: StringBuffer path = new StringBuffer(“cmd /c start D:\\SMPPPushGW_SMSCID1_Passive\\note.bat”); String result = path.substring(path.indexOf(“start”)+5, path.lastIndexOf(“\\”)); As mentioned, File API may be useful, but also URI. solved Working with strings in java : extract a particular string [closed]

[Solved] difference between replaceFirst() and trim().replaceFirst() [duplicate]

String.trim() method remove trailing and leading white spaces from the string. but since the string you are testing doesn’t have any trailing or leading white spaces, the below two will certainly return the same string. str.replaceFirst(“(.*)<?xml”,”<?xml”); str.trim().replaceFirst(“(.*)<?xml”,”<?xml”) However, your regular expression only removes leading white spaces, so if the testing string has trailing white spaces … Read more