I have a form with a collection of checkbox's for a refine search function on my website.
I am trying to pass an array in a form GET but the URL looks like:
/search?filter=foo&filter=bar&filter=green
Is there a better way to pass this in MVC? Possible like
/search?filter=foo,bar,green
Thanks in advance.
If I have the following plain string, how do I divide it into an array of three elements?
{["a","English"],["b","US"],["c","Chinese"]}
["a","English"],["b","US"],["c","Chinese"]
This problem is related to JSON string parsing, so I wonder if there is any API to facilitate the conversion.
This seems to work (compiler doesn't complain, anyway):
float adsr[4] = {0,1.0/PULSE_SPEED, 0,1};
[sequence setBaseADSR:adsr];
but I want to make it more concise and do this:
[sequence setBaseADSR:{0,1.0/PULSE_SPEED, 0,1}];
How do I do it? In javascript, I'd call stuff in the brackets an "array literal". Not sure if C languages have the same concept or terminology though.
Is there a one-line easy linq expression to just get everything from a simple array except the first element?
for (int i = 1; i <= contents.Length - 1; i++)
Message += contents[i];
I just wanted to see if it was easier to condense.
Hi,
So currently I have an array with smarty..
{foreach from=$_sequences key=k item=v}
Name => {$v.menu}
Type => {$v.type}
Step => {$v.pri}
Data =>{$v.data}
{/foreach}
which gives me
Name = Test
Type = Audio
Step = 1
Data = audio1
Name = Test2
Type = Audio
Step = 2
Data = audio2
Name = Test3
Type = Audio
Step = 3
Data = audio3
Now how would I get the data for step = 2 to echo out?
So from that foreach I only want to display "audio2"
Hi guys, I am new to VB.net and struggling to get out of VB6's way of sending data, I am doing this to send a byte array from my client to server, please advice if this is the right way, thanks:
The sending portion:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim arrNo(3) As Integer
arrNo(0) = 1400
arrNo(1) = 1000
arrNo(2) = 1200
arrNo(3) = 1350
Dim i As Integer
For i = 0 To arrNo.Length - 1
Dim outStream() As Byte = BitConverter.GetBytes(arrNo(i))
Debug.Print(arrNo(i))
serverStream.Write(outStream, 0, outStream.Length)
serverStream.Flush()
Next
End Sub
You have been given an array of size 2n+1 that have n pair of integers(can be +ve, -ve or 0) and one unpaired element.
How would you find the unpaired element.
Inspired by Raymond Chen's post, say you have a 4x4 two dimensional array, write a function that rotates it 90 degrees. Raymond links to a solution in pseudo code, but I'd like to see some real world stuff.
[1][2][3][4]
[5][6][7][8]
[9][0][1][2]
[3][4][5][6]
Becomes:
[3][9][5][1]
[4][0][6][2]
[5][1][7][3]
[6][2][8][4]
Update: Nick's answer is the most straightforward, but is there a way to do it better than n^2? What if the matrix was 10000x10000?
I have xml structure
all data comes here inside CDATA
I am using css file in it to format text and classes are mentioned in xml
Below is the code which shows data but does not format with CSS.
Thanks in advance!
var myXML:XML = new XML();
var myURLLoader:URLLoader = new URLLoader();
var myURLRequest:URLRequest = new URLRequest("test.xml");
myURLLoader.load(myURLRequest);
//////////////For CSS///////////////
var myCSS:StyleSheet = new StyleSheet();
var myCSSURLLoader:URLLoader = new URLLoader();
var myCSSURLRequest:URLRequest = new URLRequest("test.css");
myCSSURLLoader.load(myCSSURLRequest);
myCSSURLLoader.addEventListener(Event.COMPLETE,processXML);
var i:int;
var textHeight:int = 0;
var textPadding:int = 10;
var txtName:TextField = new TextField();
var myMov:MovieClip = new MovieClip();
var myMovGroup:MovieClip = new MovieClip();
var myArray:Array = new Array();
function processXML(e:Event):void
{
myXML = new XML(myURLLoader.data);
trace(myXML.person.length());
var total:int = myXML.person.length();
trace("total" + total);
for(i=0; i<total; i++)
{
myArray.push({name: myXML.person[i].name.toString()});
trace(myArray[i].name);
}
processCSS();
}
function processCSS():void
{
myCSS.parseCSS(myCSSURLLoader.data);
for(i=0; i<myXML.person.length(); i++)
{
myMov.addChild(textConvertion(myArray[i].name));
myMov.y = textHeight;
textHeight += myMov.height + textPadding;
trace("Text: "+myXML.person[i].name);
myMovGroup.addChild(myMov);
}
this.addChild(myMovGroup);
}
function textConvertion(textConverted:String)
{
var tc:TextField = new TextField();
tc.htmlText = textConverted;
tc.multiline = true;
tc.wordWrap = true;
tc.autoSize = TextFieldAutoSize.LEFT;
tc.selectable = true;
tc.y = textHeight;
textHeight += tc.height + textPadding;
tc.styleSheet = myCSS;
return tc;
}
In a ruby on rails app, I build an array of Project Names and project id values, but want to truncate the length of the names. Current code is:
names = active_projects.collect {|proj| [proj.name, proj.id]}
I have tried to add a truncate function to the block, but am getting undefined method for class error.
Thanks in advance - I just cannot wrap my head around this yet.
According to their documentation, you should use Array hydration rather than record hydration when retrieving data for read-only purposes.
However, this means I have to access the attributes of the retrieved object using arrays and string keys:
$user['Phonenumbers'][0]['number']
instead of the OO style:
$user->PhoneNumbers[0]->number
Now I'm kinda new to PHP, but in other languages I've worked with the 2nd notation would be preferable because typos would be caught at compile time while typos in string literals would not be noticed until runtime. Does this apply to PHP/Doctrine?
How to find maximum occuring integer(Mode) in an unsorted array of integers? One O(nlogn) approach I could think of is to sort. Is there any other best approach?
Hi,
I'm trying to insert a timestamp (hour:min:sec) into a two-byte array and i'm a little confused on how to accomplish this...any help is greatly appreciated!
int Hour = CTime::GetCurrentTime().GetHour();
int Minute = CTime::GetCurrentTime().GetMinute();
int Second = CTime::GetCurrentTime().GetSecond();
BYTE arry[2];
//Need to insert 'Hour', 'Minute', & 'Second' into 'arry'
Thanks!
I wanna fix a 2D board for a game. I've already fixed other panels for the gui and everything goes well. But the panel for the board cant be printed on the window. I'm a bit confused about it as i think i've followed the same ideas as for the others panels i need.
Here's what i've done:
/**
*Method used to construct the square in the area of the
*gui's grid. In this stage a GUISquare array is being constructed,
* used in the whole game as
*a mean of changing a square graphical state.
*@param squares is the squares array from whom the gui grid will be
*constructed.
*@see getSquare about the correspondance beetween a squareModel and
* a GUISquare.
*/
private void initBoardPanel(SquareModel[][] squares){
BoardPanel.setLayout(new GridLayout(myGame.getHeight(),myGame.getWidth())); //set layout
Squares=new GUISquare[myGame.getHeight()][myGame.getWidth()];
grid=new JPanel[myGame.getHeight()][myGame.getWidth()];
for (int i=0; i< myGame.getHeight(); i++){
for (int j=0; j<myGame.getWidth() ; j++){
grid[i][j] = new JPanel( );
GUISquare kout=new GUISquare(i,j);
kout.setSquare(myGame.getSquares()[i][j]);
kout.draw(myGame.getSquares()[i][j].getGoTo(),myGame.getSquares()[i][j].getNumber()); /*draw method is been called. the first parameter is the number of
the square that the player will be moved to if lands in this one
square,the second parameter is just the number of the square */
kout.setVisible(true);
grid[i][j].add(kout);
grid[i][j].setVisible(true);
BoardPanel.add(grid[i][j]);
BoardPanel.setVisible(true);
BoardPanel.setBackground(Color.WHITE);
GUISquare temp=this.getSquare(squares[i][i]);
Squares[i][j]= temp;
}
}
this.add(BoardPanel,BorderLayout.WEST);
// this.pack(); //sets appropriate size for frame
this.setVisible(true); //makes frame visible
}
/**
* Transformer for Rand/Move
* <br>This method is used to display a square on the screen.
*/
public void draw(int goTo ,int number) {
JPanel panel = new JPanel();
JLabel label1 = new JLabel(""+"Move To"+goTo);
JLabel label2 = new JLabel(""+number);
JSeparator CellSeparator = new JSeparator(orientation);
panel.add(CellSeparator);
panel.setLayout(new BorderLayout());
panel.add(label1, BorderLayout.CENTER);
panel.add(label2, BorderLayout.LINE_START);
}
I've posted only one draw method...but all versions are alike.
What's the simplest way of printing an array of primitives or of objects in Java? Here are some example inputs and outputs:
int[] intArray = new int[] {1, 2, 3, 4, 5};
//output: [1, 2, 3, 4, 5]
String[] strArray = new String[] {"John", "Mary", "Bob"};
//output: [John, Mary, Bob]
Can someone please write to me source code in Java? I have a task: create a program, that contains two dimensional array (with numbers) and the programm needs to sum zeros in each column and then get out the number of column in which the zeros are least.. thanks!
arr = ["red","green","yellow"]
arr2 = arr.clone
arr2[0].replace("blue")
puts arr.inspect
puts arr2.inspect
produces:
["blue", "green", "yellow"]
["blue", "green", "yellow"]
Is there anyway to do a deep copy of an array of strings, other than using Marshal as i understand that is a hack.
I could do:
arr2 = []
arr.each do |e|
arr2 << e.clone
end
but it doesn't seem very elegant, or efficient.
Thanks
I've got two entities, one named exercise and the other named workout. I would like to store several different exercises in each workout object.
What is the correct logic here? Create an array of exercises in each workout?
I have an table view, and the data source returns elements in the wrong order. So I have to reverse the elements in that array which returns the data for each row. How would I do that the most efficient way?
wondering if it is possible to use an array with Sass as I find my self repeating the following sort of thing:
.donkey
h2
background-color= !donkey
.giraffe
h2
background-color= !giraffe
.iguana
h2
background-color= !iguana
Hi!
I need to count number of repeating and position where they repeat of all number in multidimensional array like this:
1 2 1
1 1 2
2 3 1
And result need to be:
Number 1- two times on position 1, one time on position 2, two times on position 3
Number 2- one time on position 1, two times on position 2, one times on position 3
Number 3- 0 on position 1, one time on position 2, 0 on position 3
How i can do this? Thanks!
I'm getting the following error in my ASP.net web page:
Invalid length for a Base-64 char array.
This happens when a user activates an ajax request before the previous request completes. How can I prevent this error fro occurring?