[Solved] take a word from the user and prints it as shown below. Enter the word: Word d rd ord Word [closed]

To get the expected output, you can make the outer loop loop from word.length() – 1 down to 0 instead: #include <cstddef> // std::size_t #include <iostream> #include <string> int main() { std::cout << “Enter the word:”; if (std::string word; std::cin >> word) { for (auto i = word.length(); i–;) { // <- here for (std::size_t … Read more

[Solved] replace the matched expression from string and its next charecter?POST operation

You may want to try out the following regex. Regex101 link ((?:\?.*?&|\?)journey=)[^&]* Try out the following code to replace the value of journey to replacement string url = “http://www.whitelabelhosting.co.uk/flight-search.php?dept=any&journey=R&DepTime=0900″; string newUrl = Regex.Replace(url, @”((?:\?.*?&|\?)journey=)[^&]*”, “$1″+”replacement”); Remember to add the following to your file: using System.Text.RegularExpressions; You can do the same for DepTime using the following … Read more

[Solved] I need to compare strings in an array and store/return the longest word [duplicate]

Your post isn’t javascript, but here’s basically what you want to do. It should be easy to change it over from javascript. function compareWords(words){ var longestWord = ”; for(var i = 0; i < words.length; i++){ if(words[i].length > longestWord.length){ longestWord = words[i]; } } return longestWord; } var words = [‘gunslinger’, ‘gundam’, ‘dragon’, ‘shirt’, ‘unicorn’, … Read more

[Solved] How to concatenate a string in python?

Just pass empty string to end parameter in print function after strippping off the newline character. print (line, end = “”) print by default print the content in a new line for each iteration but by passing empty string to the end parameter, this default behaviour won’t work. If you failed to remove the newline … Read more

[Solved] How could a viable transformation look like that does convert a product-name into a valid HTML id-attribute value? [closed]

You can try this- const data = [ “2-inch leg extension”, “2′ x 8′ Overhead Garage Storage Rack”, “4 Drawer Base Cabinet 16-1/2\”W x 35\”H x 22-1/2\”D”, “24\” Long Tool Bar w/ Hooks Accessory” ]; const res = data.map(str => str.replace(/[^a-z\d\-_]/ig, ”)); console.log(res); If you need any prefix with the ID then add it like- … Read more

[Solved] How to print numbers in the following pattern with .NET

The problem is in the MakeALine method. You actually concat the number with itself, so for input 1 you actually get “1” + “1”. Instead you should repeat the string representation of your number k times. For this you can use Enumerable.Repeat in the following way: static string MakeALine(int k) { return String.Concat(Enumerable.Repeat(k.ToString(),k)); } 3 … Read more

[Solved] How to import a String from a a different Class

This has to do with the scope of your variables. You can find more informatnion here. Currently the variables stored in class A have package-private scope. There are really two ways to do what you are describing. The better solution would be to provide a getter method within classA: public String getA(){ return this.A; } … Read more

[Solved] Need some advice on split() method in Java [closed]

Guessing that you want to split by the comma then this will make it String toSplit = “LXI H, 2000H, MOV M A”; // this is a regular expression, you should study regular expressions too String[] split = toSplit.replace(“,”, “”).split(” +”); for (String s : split) System.out.println(s); Read the String class in the java API … Read more

[Solved] How do you make a c++ program search for a string? [closed]

First open an ifstream to open your file then check for the string: #include <iostream> #include <fstream> #include <string> using namespace std; int main () { string line; ifstream myfile (“example.txt”); if (myfile.is_open()) { while ( getline (myfile,line) ) { if(line.find(“the string to find”) != string::npos) { //line found, do something } } myfile.close(); } … Read more

[Solved] Convert string to Ordered Dictionary [closed]

You can try something like this : input_st = “Field1:’abc’,Field2:’HH:MM:SS’,Field3:’d,b,c'” output_st = {item.split(“:”)[0]:”:”.join(item.split(“:”)[1:]).replace(“‘”, “”) for item in input_st.split(“‘,”)} outputs : {‘Field1’: ‘abc’, ‘Field2’: ‘HH:MM:SS’, ‘Field3’: ‘d,b,c’} Kind of ugly but it does the job. 4 solved Convert string to Ordered Dictionary [closed]

[Solved] In JavaScript, what is the simplest way to insert text into a string?

Use: var queryStringParts = queryString.split(‘&’); var pairs = queryStringParts.map(function(str) { return str.split(‘=’) }) var rewrittenParts = pairs.map(function(pair){ return ‘slides[0].’ + pair[0] + ‘=’ + pair[1] }); var newQuerystring = rewrittenParts.join(‘&’); As was pointed out in the comments, in this specific case we could skip the split into pairs step and just do var queryStringParts = … Read more

[Solved] How to replace several characters on a single string to desired characters (java)?

public class TranslateChar { /** @param args */ public static void main(final String[] args) { final Map<Character, Character> mapCharCod = new HashMap<>(36); final Map<Character, Character> mapCharDecod = new HashMap<>(36); mapCharCod.put(‘A’, ‘Z’); mapCharCod.put(‘B’, ‘X’); mapCharCod.put(‘C’, ‘Y’); mapCharDecod.put(‘Z’, ‘A’); mapCharDecod.put(‘X’, ‘B’); mapCharDecod.put(‘Y’, ‘C’); final String toCod = “CAB”; StringBuilder sb = new StringBuilder(“{“); for (final char c … Read more

[Solved] isnt everything where it should be, why the segmentation fault?

Here char *firstName[50]; firstName is array of 50 character pointer, and if you want to store anything into each of these char pointer, you need to allocate memory for them. For e.g for (int counter = 0; counter < 10; counter ++) { firstName[counter] = malloc(SIZE_FIRST); /* memory allocated for firstName[counter], now you can store … Read more