stirng is the special kind of array and compatible with bytes. Solidity does not provide much string operation and hence we can rely on bytes to carry out any string related operations like null check, length ...
pls find below the modified code to check for the string limit. If supplied styring lenght is more than required then this funcction would revert the function call.
In ther latest solidity release, 'throw' has deprecated, thats why I have used 'revert'.
pragma solidity ^0.4.4;
contract Test{
string data;
uint stringLimit;
function setVariable(string str) {
bytes memory strBytes = bytes(str);
if(strBytes.length >= stringLimit)
revert;
else
data = str;
}
}