variables

exploding a string with variable

拥有回忆 提交于 2020-01-16 00:56:05
问题 I'm trying to manipulate a path to an image using php. The path has a variable userdirectory in it, so i'm struggling with how to write this. Ive used to do : $texthtml = $content; if (preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $texthtml, $image) ) { $promopic = $image['src']; } to find if there is an image in my content and make a variable out of it. that works, but i need to alter my code to load image from a thumbnail directory for pageload reasons. an image src looks like this :

How to hide or delete the zero in my bash script?

左心房为你撑大大i 提交于 2020-01-15 15:33:51
问题 This is my script: echo -n "number 1 :"; read bil1 echo -n "number 2 :"; read bil2 multiple=$(echo $bil1*$bil2 |bc -l |sed -e 's/^\./0./' -e 's/^-\./-0./'); echo " Your result : $bil1 * $bil2 = $multiple "; If I input 9.5 for $bil1 and 300 for $bil2 , the result is 2850.0 . I want the result: Your result : 9.5 * 300 = 2850 How do I hide or delete the zero at the end of the result? I.e. show only 2850 ? 回答1: Add the following part to your sed command (at the end): -e 's/\.0*$//' (Delete a dot

How to hide or delete the zero in my bash script?

余生颓废 提交于 2020-01-15 15:31:15
问题 This is my script: echo -n "number 1 :"; read bil1 echo -n "number 2 :"; read bil2 multiple=$(echo $bil1*$bil2 |bc -l |sed -e 's/^\./0./' -e 's/^-\./-0./'); echo " Your result : $bil1 * $bil2 = $multiple "; If I input 9.5 for $bil1 and 300 for $bil2 , the result is 2850.0 . I want the result: Your result : 9.5 * 300 = 2850 How do I hide or delete the zero at the end of the result? I.e. show only 2850 ? 回答1: Add the following part to your sed command (at the end): -e 's/\.0*$//' (Delete a dot

Cannot find symbol while loop

◇◆丶佛笑我妖孽 提交于 2020-01-15 15:24:13
问题 Hello I am creating an algorithm to take int x and convert it to the desired base being int y. example 7 base 3 = 21. void printXBaseY(int x, int y) { boolean active = true; while(x >= y) { int a = x % y; int b = x / y; String first = "" + a; String second = "" + b; String answer = "" + first + second; } String answer = "" + first + second; println(x + " base " + y + " is " + answer); } } at String answer it has error cannot find symbol - variable first, can anyone explain why it cannot find

dynamic variable names in matlab

廉价感情. 提交于 2020-01-15 12:21:46
问题 I wish to expand a structure ( bac ) with a number of fields from another structure ( BT ). The names of these fields are contained in the cell array ( adds ) as strings. this is what i have now (and obviously doesn't do the job, explaining this post): for i=1:numel(adds) eval(genvarname('bac.',adds{i})) = eval(strcat('BT.',adds{i})); end I also tried using sprintf , which did not seem to work for me. I feel confident one of you knows how to do it, since I feel it should be rather easy. 回答1:

dynamic variable names in matlab

亡梦爱人 提交于 2020-01-15 12:21:44
问题 I wish to expand a structure ( bac ) with a number of fields from another structure ( BT ). The names of these fields are contained in the cell array ( adds ) as strings. this is what i have now (and obviously doesn't do the job, explaining this post): for i=1:numel(adds) eval(genvarname('bac.',adds{i})) = eval(strcat('BT.',adds{i})); end I also tried using sprintf , which did not seem to work for me. I feel confident one of you knows how to do it, since I feel it should be rather easy. 回答1:

echo the set of variables while going through a loop

六月ゝ 毕业季﹏ 提交于 2020-01-15 11:59:24
问题 Can someone help me. I've been trying alternatives but I still get the same output. Here is my script #!/bin/sh field1="a" field2="s" field3="d" field4="f" field5="g" for i in {1..5} do var1="field"$i echo $var1 var2="$"$var1 echo $var2 echo $field1 done Here is my output field1 $field1 a field2 $field2 a field3 $field3 a field4 $field4 a field5 $field5 a what I'm trying to do is get an output like a s d f g 回答1: You're looking for ${!var1} — a Bash-specific shell parameter expansion. field1=

what do the square brakets mean in vb.net in this string

冷暖自知 提交于 2020-01-15 11:54:42
问题 What do the square brakets mean in vb.net in this variable below defining as [String] Dim client As New WebClient() Dim htmlCode As [String] = client.DownloadString("http://www.stackoverflow.com") 回答1: It's useless in your example. Brackets are there to use reserved keywords for what they aren't, for example Dim [String] = "asdf" which will create a var named "String" (which is stupid, but...) 回答2: It allows you to use a reserved word in your code. There is some mis-information about this as

what do the square brakets mean in vb.net in this string

对着背影说爱祢 提交于 2020-01-15 11:54:29
问题 What do the square brakets mean in vb.net in this variable below defining as [String] Dim client As New WebClient() Dim htmlCode As [String] = client.DownloadString("http://www.stackoverflow.com") 回答1: It's useless in your example. Brackets are there to use reserved keywords for what they aren't, for example Dim [String] = "asdf" which will create a var named "String" (which is stupid, but...) 回答2: It allows you to use a reserved word in your code. There is some mis-information about this as

dynamic variable declaration function matlab

强颜欢笑 提交于 2020-01-15 11:23:09
问题 How to declare dynamic variable names in Matlab , and the function returns those variables? I want the function that returns the string with dynamic variable name and returns only when number of iterations n is given. I have tried the my following code: function [var] = myFunc(n) for ii=1:n var= ['var' num2str(ii)]; var{ii} = strcat('(some srting', var,')'); eval(['var' num2str(ii) ' = var']); end end 回答1: CASE 1: This will get you the eval strings that you can use later on to actually get