[Solved] How can I change id in string

Since you are already using jquery: for (var i = 0; i < tab.length; i ++) { tab[i] = $(tab[i]).find(“tr”).first().attr(“id”, “id_” + i); } What this does: Create jquery objects from the html string: $(tab[i]) Find the first tr object: .find(“tr”).first() Set the attribute “id” of the object to “id_” + i: .attr(“id”, “id_” + … Read more

[Solved] Complicated regex in PHP

try this: <?php $q1 = “{Hello|Hi} sir.”; $q2 = “{How are you?|How are you doing?}”; $q = substr($q1, 1, strpos($q1,’}’)-1); $q_end = substr($q1, strpos($q1, ‘}’)+2); $parts = explode(‘|’,$q); echo “<select name=\”q1\”>\n”; foreach($parts as $part){ echo “\t<option value=\””.strtolower($part).”\”>$part</option>\n”; } echo “</select>\n”; echo $q_end . “\n”; $q = substr($q2, 1, strpos($q2, ‘}’)-1); $parts = explode(‘|’,$q); echo “<select … Read more

[Solved] How to replace specific part of a string (replace() dosen’t help…) [closed]

I just got a trick for you to achieving what you want. a = “hello world, hello there, hello python” a = a.replace(“hello”,”hi”,2).replace(“hi”,”hello”,1) print(a) So what exactly 2nd Line does it it is replacing first two occurrence of hello to hi and then replacing 1st occurrence of hi to hello. Thus getting the output you … Read more

[Solved] Python: AttributeError: ‘str’ object has no attribute ‘readlines’

In order to give a good answer to jill1993’s question and take the MosesKoledoye’s answer : abproject = (“C:/abproject.build”) abproject is a string object. Furthermore, you write : with open(“C:/abproject.build”, “r+”) as script So if you want to solve your script error, you have to write : with open(“C:/abproject.build”, “r+”) as script, open (“C:/tempfile.build”,”w+”) as … 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] PHP – Replace part of a string [closed]

Use a regular expression. str_replace will only replace static values. $RAMBOX = ‘hardwareSet[articles][123]’; $Find = ‘/hardwareSet\[articles\]\[\d+\]/’; $Replace=”hardwareSetRAM”; $RAMBOX = preg_replace($Find, $Replace, $RAMBOX); Output: hardwareSetRAM The /s are delimiters. The \s are escaping the []s. The \d is a number. The + says one or more numbers. Regex101 Demo: https://regex101.com/r/jS6nO9/1 If you want to capture the … Read more

[Solved] Hide an element and show another if page is taking too long to load [closed]

It’s not something I’d usually recommend but here’s a pretty hacky solution. const video = document.querySelector(“#video-element-id”); let tooSlow = false; let timeout = setTimeout(() => { tooSlow = true; …logic to change header clearTimeout(timeout); }, 1000); video.addEventListener(‘loadeddata’, () => { console.log(tooSlow ? ‘too slow’ : ‘loaded’); clearTimeout(timeout); }); * EDIT – or you could do … Read more

[Solved] Spaces not being replaced with newlines

Welcome to C! You have allocated no memory so you error. Use malloc to allocate the memory. I have made this code that works for you: void f(char*s,char*toString) { char c,i=0,j=0; int num=0; while(c=*(s++)) { toString[num]=c; // putchar(c); if(c==’ ‘)++i; if((j<4&&i==7)||(j>=4&&i==6)) { i=0; ++j; toString[num]=’\n’; // putchar(‘\n’); } num++; } } state_t initial_user_state_to_c(char * string) … Read more

[Solved] Replace with php each font size=”” to font-size: ; how to? [closed]

You can use preg_replace(). http://php.net/manual/en/function.preg-replace.php $str=”Hello <font size=”4″>today</font> is my <font size=”3″>special day</font> and am <font size=”11″>ready</font> for it…”; preg_replace(‘/<font size=”(\d+)”>(.+?)<\/font>/’, ‘<span style=”font-size:$1;”>$2</span>’, $str) Output: Hello <span style=”font-size:4;”>today</span> is my <span style=”font-size:3;”>special day</span> and am <span style=”font-size:11;”>ready</span> for it… 4 solved Replace with php each font size=”” to font-size: ; how to? [closed]

[Solved] regular expression to replace div [closed]

This solution uses 2 Replace calls which might be OK if the code is not executed too frequently: string input = @”<div class=””tr-summaryinfo””>’ <p class=””tr-summaryitem””>test </> </div>”; string result = Regex.Replace(input, “<div class=\”tr-summaryinfo\”>(.*?)</div>”, “<ul class=\”tr-summaryinfo\”>$1</ul>”, RegexOptions.Singleline); result = Regex.Replace(result, “<p class=\”tr-summaryitem\”>(.*?)</p>”, “<li class=\”tr-summaryitem\”>$1</li>”, RegexOptions.Singleline); Note that you need ? in the patterns to avoid the … Read more