When I am trying to convert bytes to characters, flex stops conversion if it encounters unicoder number 0 (NUL). Why is it so? Flex is able to convert 1-256 unicode numbers except 0.
In the following example, Alert window does NOT display any text, because parameters started with 0 while forming the string message from unicode numbers.
<?xml version="1.0" encoding="utf-8"?>
<s:Application name="Alert" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="init();">
<s:controlBarContent>
<s:Button id="btn"
label="Show alert"
click="init();"/>
</s:controlBarContent>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
protected function init():void {
// if string message value is String.fromCharCode(78,0);, then Alert displays as N
//Here, since message starts with unicode character 0, Alert displays nothing.
//Flex string is getting stopped if it encounters unicode 0, why is it so?
//but flex string supports other contorl ascii characters except NUL (0)
var message:String=String.fromCharCode(0, 78, 1);
Alert.show(message, "", Alert.YES | Alert.NO | Alert.OK | Alert.CANCEL);
}
]]>
</fx:Script>
</s:Application>
I am not sure why flex is not able to convert unicode 0 character?
Temporarily, I am converting them to 32 (empty space) if it is 0.
Thanks in advance.
Good question!. I try it on my Flash Builder 4.6.
As i Know is String.fromCharCode(num),num depend from keycode
if your get the num begin at 1~Max and it not include in keycode list,
it will return whitespace. But if the num is 0,fromCharCode will return undefined ref.
But you cloud get string length from this string array:
{undefined,h}.length = 2
{undefined,h} make to string = undefined. remember it as X.
i will show you the Math
h+X = h+undefined.
you could try this:
var str:String = String.fromCharCode(0,104);
var str1:String = String.fromCharCode(1,104);
var str2:String = String.fromCharCode(104,0,104);
Alert.show(str);
Alert.show(str.length.toString());
Alert.show(str1);
Alert.show(str1.length.toString());
Alert.show(str2);
Alert.show(str2.length.toString());
You will see str2 show you something different.
{h,undefined,h}.length = 3
for each this for string ref will be:
h+X = h+undefined.
I Guess it's reason is String.fromCharCode Function don't catch
if(codenum == 0){return whitespace}
It may use as switch or for or others way begin the code num at 1.
C strings are terminated by a null byte \0 character.
Similar to C, I believe ActionScript interprets this as a null terminated string.
Because 0 byte is not actually a string char. If you are working with binary data keep it in ByteArray
Related
Using Qt 4.8.4 on Windows platform and trying to use QXmlQuery without any luck. Obviously researched this topic without finding a solution.
Here is the xml file
<?xml version="1.0" encoding="UTF-8"?>
<root>
<a>abc</a>
<a>def</a>
<a>123</a>
</root>
The code looks like this;
QFile temp("C:/Temp/data.xml");
bool opened = temp.open(QIODevice::ReadOnly | QIODevice::Text);
QXmlQuery q;
q.bindVariable("file", &temp);
q.setQuery("declare variable $file external;doc($file)//root");
bool valid = q.isValid();
QStringList items;
q.evaluateTo(&items);
int len = items.size();
File is opened successfully, QXmlQuery is valid but QStringList contains 0 items. Why does not the query return a result?
Changing the XQuery from
q.setQuery("declare variable $file external;doc($file)//root");
to
q.setQuery("declare variable $file external;doc($file)//root/string()");
solved the problem.
The docs did actually state "The query must evaluate to a sequence of xs:string values. If the query does not evaluate to a sequence of strings, the values can often be converted by adding a call to string() at the end of the XQuery."
http://qt-project.org/doc/qt-4.8/qxmlquery.html#evaluateTo-3
I have an asp.net 4 textbox control that has it's text being dynamically populated by some java script. A Google Maps call to be exact. It's giving me mileage from 1 point to another. When the text displays, it shows " 234 mi" I need to get rid of the "mi" part of this text because the text is being converted to an Int32 Updating a table in my DB.
Basically I can only have an INT. Nothing else in the text box. How do I get rid of the "mi" at the end of the text?
Thanks
C#
EB
On the postback, before you save it you could:
var saveValue = Int32.Parse(tbTarget.Text.Replace("mi", string.Empty).Trim());
If your working with a variable length of chars (say someone enters miles instead) then your must do a foreach against the string (an array of char) and check isnumeric on each char.
A simple String.Substring works also:
String leftPart = TxtMileAge.Text.Substring(0, txt.IndexOf(' '));
int mileAge = int.Parse(leftPart);
This retrieves the part of the String in the range of 0 - indexOfWhiteSpace and converts it to an int
Edit: Since the value can have decimal places (as you've commented), you need to parse it to double, round it and then cast it to int:
var txtEstDistance = new TextBox() { Text = "40.2 mi" };
String leftPart = txtEstDistance.Text.Substring(0, txtEstDistance.Text.IndexOf(' '));
double distanceMiles = double.Parse(leftPart, System.Globalization.CultureInfo.InvariantCulture);
int oDdstanceMiles = (int)Math.Round(distanceMiles, MidpointRounding.AwayFromZero);
I'm trying to learn Flex, I setup a simple Air application with PHP server as dataserice...
In my php class there is a function counttotal that return a simple int value.
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:demologicaclass="services.demologicaclass.*"
width="682" height="397" showStatusBar="false" initialize="init()">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
protected var count:int = 0;
protected function init():void
{
counttotalResult.token = logicaservice.counttotal();
count = counttotalResult.lastResult as int;
}
protected function get_count():void
{
Alert.show(count as String);
}
.....
.....
<s:Label id="countitems" left="10" bottom="39" width="221" height="21"
fontSize="20"
fontWeight="bold" text="{counttotalResult.lastResult as String}"/>
<s:Button right="10" bottom="39" label="Controlla" click="get_count();"/>
In the label I got the correct value, but I can't save and show the value into/from a simple variable...
That's because using the keyword as will make Flex to try to cast a type to another, with a risk that the cast fails. Here, you try to cast a String as an integer, which basically means you do the following :
take 'blabla' and check if it's an integer. If it is, put its value in
count, otherwise put null in it.
What you want to do is transtype (not sure about the word, though) a String to an integer. To do this, use the following syntax :
count = int(Number(counttotalResult.lastResult));
The above means
Take lastResult, and convert it into a Number, and then into an int.
The conversion can fail (but it wont, as long as lastResult is the string representation of a valid number), and the syntax could be shorter, but in a nutshell, that's the difference between casting a type to another, and converting a type to another.
what's the easiest way to cut string in Flex ?
I mean, I have a sequence of urls, I want them at most 60 characters length. If they are longer they should be cut and "..." should be added at the end.
<mx:LinkButton label="{bookmarksRepeater.currentItem.name}" click="navigateToURL(new URLRequest(event.currentTarget.label.toString()))" />
thanks
if you can run full flex code in the label="" section, perhaps set the label to this:
it's a conditional statement: if the name length is less than or equal to 60, just use the name, otherwise use the first 57 characters of the name and '...'
bookmarksRepeater.currentItem.name.length <= 60 ? bookmarksRepeater.currentItem.name : bookmarksRepeater.currentItem.name.substr(0, 57) + '...'
substr(startIndex:Number = 0, len:Number = 0x7fffffff):String
Returns a substring consisting of the characters that start at the specified startIndex and with a length specified by len.
from HERE
How to add mnemonic character to a regular button in Flex? Show me some examples.
Here is an extended button component, that can help you deal with the task:
package test
{
import mx.controls.Button;
import flash.text.TextFormat;
public class ShortcutButton extends Button
{
private static const underlineTF:TextFormat = new TextFormat(null, null, null, null, null, true);
public function ShortcutButton()
{
super();
}
protected var shortcutPosition:int = -1;
override public function set label(value:String):void
{
shortcutPosition = value.indexOf("~");
if (shortcutPosition >= 0)
value = value.substring(0, shortcutPosition) + value.substring(shortcutPosition + 1);
super.label = value;
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if (shortcutPosition > -1 && shortcutPosition < textField.text.length - 1)
textField.setTextFormat(underlineTF, shortcutPosition, shortcutPosition+1);
}
}
}
Just place "~" symbol before the symbol you want to underline to show it's a shortcut mnemonic character.
Example (you'll have to add xmlns:test="test.*" to the container component):
<test:ShortcutButton label="~Update" />
1st Solution:
<?xml version="1.0" encoding="ISO-8859-1"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
Just set the encoding value of the mxml file and you can type the
special character right in. ISO-8859-1 encoding type works for me with
the © symbol.
2nd Solution:
Let's Example, The © escape sequence is only defined for HTML, and not XML.
According to the W3C XML 1.0 recommendation, only a handful of such
mnemonic escape sequences are defined. However, you can include other
characters using numeric character references by specifying their
Unicode code points.
See: http://www.w3.org/TR/REC-xml/#syntax
For instance, the copyright symbol can be expressed as either (without
the double quotes): "©" or "&xA9;" (hexadecimal). This will work
provided the font that you're using has the glyphs for the code point
that you're referencing (as Unicode defines characters and symbols from
a very wide assortment of languages, many of which will not exist in
all fonts.
For a list of all the Unicode characters and their code points, you can
consult the Unicode code charts available here:
http://www.unicode.org/charts/
You can also lists online giving the code points for some of the more
common symbols, and most operating systems now come with a character or
symbol picker (e.g. Microsoft Windows' character map utility) that'll
oftentimes list the characters' code points as well.
http://livedocs.adobe.com/flex/3/html/help.html?content=accessible_7.html