Is there a way to get the cursor position index of html text field

I'm trying to work on a text pad like MC with "insert text at
position X" and "find and replace" can anyone tell me how to find
the cursor index of an html text field. Selection.getBeginIndex() ,
Selection.getEndIndex(), Selection.getCaretIndex() as far as I know
these methods only work with text and not htmltext.
What I'm trying to do is assign different parts of the string
to variables so that I can combine them to reconstitute my html
string.

enfantterrible:
If I understand correctly, you want the corresponding
position in the
htmlText propery of the caret index (which as you point out
is only the
position in the plain text version of the textfield content).
Below is how I would do it. Maybe there's an easier or more
efficient
way (using XML objects etc), but I don't know it. You could
conduct all
your string searches in the plain text and then convert the
result to
the html positions. I didn't build this to accept negative
parameters
for the pos parameter (e.g. from end of string backwards) but
the
function could be adapted to do this too if necessary. The
test data is
not proper html from a text field, but it doesn't really
matter what it
is so long as its formatted correctly. It just separates the
tags from
the content to enable apples with apples comparison.
//some test data
var testStringXML = "<format>Hel<b>lo i can't
t<i>ell you h</i>ow hap</b>py I
am.</format>";
var undecoratedString = "Hello i can't tell you how happy I
am.";
//the conversion function
function findDecoratedPosition(pos:Number, xmlString:String,
test:Boolean):Number {
//anything between '<' and '>' should be excluded from
plain text search.
//create an array of array elements (n=2) consisting of tag
then plain text
//requires correctly formatted xml/html
var tempArr:Array = xmlString.split("<");
for (var aa = 0; aa<tempArr.length; aa++) {
tempArr[aa] = tempArr[aa].split(">");
//remove the first and last elements of the new array (these
are empty)
tempArr.pop();
tempArr.shift();
//find the corresponding plaintext location and calculate
the "decorated" position
var retPos:Number = 0;
var posCount:Number = 0;
for (var aa = 0; aa<tempArr.length; aa++) {
retPos += tempArr[aa][0].length+2+tempArr[aa][1].length;
//+2 allows for missing < and >
posCount += tempArr[aa][1].length;
if (posCount>pos) {
return (retPos+(pos-posCount));
//out of range
return -1;
//test code:
for (var aa = 0; aa<undecoratedString.length; aa++) {
var altPos = findDecoratedPosition(aa, testStringXML);
trace(undecoratedString.charAt(aa)+" in position "+aa+"
plainText equates to position "+altPos+" in the decorated version
["+testStringXML.charAt(altPos)+"]");
}

Similar Messages

  • Changing the cursor position in an input text field and Removing leading numeric zeros

    Flash8 - AS2
    It's good to be back after all these years and thanks for the faithfull folks like kglad, Ned Murphy, Rothrock and all the others who give so much of themselves to make this forum a success!
    My Problem:
    I have an input text field that is named in the properties box as 'numberOfKids'.
    When the program is executed, and a delete or backspace is pressed the input textfield goes blank
    and any calculations that use 'numberOfKids' shows NaN.
    I have trapped the NaN and undefined so that a numeric 0 shows up instead of a blank.
    There are two problems:
    First problem:
      The cursor is to the left of the zero, so the first number inputted by the user is 10x larger than what they want.  0 becomes 10.
    Question:  How do I get the cursor to move to the right of the 0?
    Second Problem: 
      When I manually move the cursor to the right of the 0 and input a number, say 4, it shows up as 04.
    Question 2:  How do I delete the leading numeric zero in the input textfield?
    Thanks for the help.
    Here's the code I am using:
    calculateChildWeight = function () {
    if (isNaN(numberOfKids)) {
      numberOfKids = 0;
    if ((numberOfKids) == undefined) {
      numberOfKids = 0;
    if (numberOfKids>=0 && numberOfKids<=137) {
      numberOfKids = numberOfKids;
    } else {
      numberOfKids = 0;
    if (isNaN(adjustedChildWeight)) {
      adjustedChildWeight = 0;
    if ((adjustedChildWeight)=undefined) {
      adjustedChildWeight = 0;
    adjustedChildWeight = Number(numberOfKids*(-100));
    //numberOfKids.setSelection(numberOfKids.length, numberOfKids.length);
    //if (numberOfKids.length=2 && numberOfKids<10) {
      // remove the first character or leading zero
    //  numberOfKids = numberOfKids;

    Thanks Rothrock for being so  patient.
    I'm lost!
    I go back to a brand new flash file to try and implement the textfields as a stand alone test document.  I have lost the concept I think.
    I created on the stage of a blank .fla file  4 text fields, 2 input and 2 dynamic.  I gave them an instance name in the properties box.  I use this instance name.text to find the value of the field.  I use the parseInt to put that value into a numeric variable for calculation.  The results are put to the appropriate textfield.
    All seems to work except one of my input text fields.   I use the value of this field  to calculate:
    revisedValue = parseInt(numberOfKids.text);
    revisedValue = revisedValue*(-100);
    The problem now is that if the numberic '2' is inputted into numberOfKids, numberOfKids.text shows up as 200 and a trace shows up as '2NaN'.
    Flash is logical and consistant, I must conform to it but I'm in the dark.
    (( Concerning the forum:  If I click on helpful, which your posts have been in directing me, does that blank out the possibility of selecting the correct answer in the future???))

  • Is there a way to change the cursor hotspot systemwide on Mountain Lion?

    Hello community.
    Is there a way to change the cursor hotspot on Mountain Lion, systemwide?
    Like editing the original cursor file (or downloading one) and replacing the original one?
    Reason: when I enlarge the arrow, the "absoulute" tip (top of the white outline) gets distant from the internal tip (top of the black core), so sometimes the white outline needs to stick out if I want to click the approprate area - because the hotspot is on the internal tip. To me it's counter-intuitive. I would prefer to have the hotspot on the absolute edge of the cursor (tip of the white outline). This is not debatable - this is my private preference, and I've read today that it's not only mine - there is a number of users who want the same.
    I know it's always been like this on Macs, so please avoid questions like "why to you want that", answers like "get used to it" or any kind of hostility, for these are useless. The quiestion is how can I change it, if possible.
    Thanx guys!

    I don't know how you get to the System folder in Mavericks; and even if I found the folder with the alternative cursors in it, I would have no way of switching to any of them.  The designers have obviously not anticipated that anyone would wish to do this.
    The System Preferences has an adjustment under Accessibilty which allows the user to change the size of the cursor, but nothing else.
    So I guess that there is no way to make the change without actually re-engineering the System somehow.
    If someone can find a way, I will be most pleased to be enlightened; only please make the directions explicit.

  • Is there a way to get the voice memos from my iPhone on to my pc?

    Is there a way to get the voice memos from my iPhone on to my pc?

    See http://www.tech-recipes.com/rx/6403/iphone-transfer-voice-memos-from-iphone-to-c omputer/.

  • Is there any way to get the height/width of an image before importing it in the indesign document.

    Hi All,
    I need to obtain an image's attributes such as dimensions (height, width in pixels) without placing image in indesign document.
    I have full path of the image (say abc.jpg is stored at c:\my pic\abc.jpg).
    I have obtained the IDFile for this image, tried getting size using GetFileSize() which correctly return size in bytes.
    Is there any way to get the height/width of image without importing it in the indesign document.
    Please, give me some hints. I have spent quite a lot time digging in CHM. I have searched in FileUtils, IDFile API's but found no method which serves this purpose.
    At this point I am clueless where to search next.
    Any help will be appriciated.
    Just a point to mention, I am able to get image height and width for an image in indesign doc though Its not my requirement.
    Thnx,
    D.

    You might be able to examine the contents of the PlaceGun after calling kImportAndLoadPlaceGunCmdBoss without actually placing the image in a document. Not sure, but would be worth looking at.
    Otherwise you will probably have to write platform specific code, ideally with a generic platform-independant wrapper (see SDKSamples/paneltreeview/PlatformFileSystemIterator).
    For the Mac, look at CGImageGetWidth() etc., not sure what the best option is for windows.
    Perhaps Quicktime could provide you with a platform independant solution.

  • Is there a way to get the songs back after you do a sync and erase? I no longer have them stored on my harddrive.

    Thanks to a wonderful geeksquad agent all my songs have been deleted from my ipod. They had to restore my computer so the ones I downloaded are no longer on my harddrive or in itunes. Is there a way to get the songs back after you do a sync and erase?

    If they are on the iPod there are third-party programs that will transfer then to  a computer. See:
    Copy music from Ipod to new computer...: Apple Support Communities
    If they ae not on either the iPOd or the computer they are gone.

  • I still have my iPod Nano 3rd generation, but my old computer crashed and I did not have itunes backed up, so I lost my library. Is there a way to get the songs from my old ipod to new computer library and then on to the new ipod?

    I still have my iPod nano 3rd generation, but my old computer crashed and I did not have itunes backed up. Is there a way to get the music from ipod to new computer library and then on to the new ipod ?

    Save all the photos from your Droid into a folder on your computer.
    Connect your device to your computer. On iTunes left Pane, select iPhone under 'Devices'; then on the right Pane, select PHOTO tab.  Make sure Sync Photo box is checked, and "from" box selected the folder that has Droid's photos.  Then click the SYNC or APPLY button on the lower right window.

  • Is there a way to put the cursor at a specific location in a RichTextBox?

    Is there a way to put the cursor at a specific location in a RichTextBox?
    The following code places the cursor at the start of a RichTextBox:
        RichTextBox RTbx
        RTbx.Focus();
        TextPointer tp = RTbx.CaretPosition;
        tp = tp.DocumentStart;
        RTbx.CaretPosition = tp;
    Not sure how to place it at a specific location other than start and end.
    The RichTextBox has contents.  At this point in the code, I do know the specific "word" in the contents, as well as the position (number of chars) where that word is located.  I just need to programmatically place the cursor at that location.
    bhs67

    Oh sorry, I see I missed something out my original reply.
    I have markup:
    <Grid>
    <RichTextBox Name="rtb">
    <FlowDocument>
    <Paragraph >This is the first paragraph</Paragraph>
    <Paragraph >TSecond paragraph is here</Paragraph>
    </FlowDocument>
    </RichTextBox>
    </Grid>
    Code - this is the window contentrendered event
    private void Window_ContentRendered(object sender, EventArgs e)
    rtb.Focus();
    // TextPointer moveTo = rtb.CaretPosition.GetNextInsertionPosition(LogicalDirection.Forward);
    TextPointer moveTo = rtb.CaretPosition.GetPositionAtOffset(9, LogicalDirection.Forward);
    if (moveTo != null)
    rtb.CaretPosition = moveTo;
    I see the cursor between the t and he of the second "the".
    Note that there are numerous other options such as the commented out line.
    Hope that helps.
    Recent Technet articles: Property List Editing;
    Dynamic XAML

  • Is there a way to get the correct order from the dependent types of a sche

    Hi ,
    I have a CT facing the following problem:
    When trying to built a SQL script to create all the object types within a schema using the DBMS_METADATA packages.
    Did insert in a table the names of the types that will be exported following a concrete order, next loop into the table and call the DBMS_METADATA package for each row.
    These type are depedent between them, there are some type attributes calling other types and here the issue
    First : try to generate the order by created column of dba_objects and when the generated SQL script is launched a lot of type appearing as incomplete state due to the order isn't correct.
    Second : try to insert the table ordering by object_id colums of dba_tables view, it appears incomplete types too.
    Currently want to insert the table using a recursive query with connect by against the dba_type_attrs starting with the rows when ATTR_TYPE_NAME is not null (the types that are called by other types), but this way has a issue dificult to resolve: the roots of hierarchy are the rows when ATTR_TYPE_NAME is not null and we've dependencies between roots nodes
    The question is is there a way to get the correct order from the dependent types of a schema?
    Platform: IBM SP AIX
    DB version: 9.2.0.7
    Any help will be appreciated .
    Thanks in advance.

    The xxx_dependencies view should give you the dependencies betwee nthe various types. I would look at something along the lines of:
    SELECT object_name, referenced_name
    FROM (SELECT o.object_name, d.referenced_name
          FROM user_objects o, user_dependencies d
          WHERE o.object_name = d.name(+) and
                o.object_type = d.type(+) and
                d.referenced_type(+) = 'TYPE' and
                o.object_type = 'TYPE')
    START WITH referenced_name IS NULL
    CONNECT BY PRIOR object_name = referenced_nameThe outer join between user_objects and user_dependencies is required to generate the names of types which are not dependent on other types, or do not have other types dependent on them.
    HTH
    John

  • Can't remember my security questions and can't access my back up email address is there a way of getting the information sent to another email?

    Can't remember my security questions and can't access my back up email address is there a way of getting the information sent to another email?

    No. You need to ask Apple to reset your security questions; ways of contacting them include phoning AppleCare and asking for the Account Security team, clicking here and picking a method for your country, and filling out and submitting this form.
    They wouldn't be security questions if they could be bypassed without Apple verifying your identity.
    (103501)

  • Is there a way to get the history from find my iphone?

    My iPhone disappeared from my car while it was valet parked at the airport. I did a find my phone when I realized I had left it in the car, and it showed the location to be valet parking lot. I assumed all was well, did a remote lock operation, and enjoyed the vacation. Is there any way to get the log from find my phone to show that it was where it was when I did the find operation?
    Sam

    No.

  • Is there a way to force the cursor into a string control when a vi is called

    In a .vi I'm wrighting I need to input a new serail number at the beginning of each run. Is there a way to force the cursor into the string control box every time the start screen returns? eliminating the need for the operator to move the mouse around and click.
    I would like to THANK all that have replied to my questions in the past. It has been a big help!
    Thanks
    TeBlues

    ah, problem solved.  what a community.
    Message Edited by Space_Flight on 11-20-2006 10:08 AM
    Attachments:
    keyfocus.jpg ‏83 KB

  • When using an external (ergonomic mouse) is there any way to get the wheel to scroll one full page at a time?

    When using an external (ergonomic mouse) is there any way to get the wheel to scroll one full page at a time? Much appreciated.

    I can't use the keyboard to scroll. I need to keep my hand on the mouse, otherwise I'd never get anything done. Since I have no problem getting Firefox to scroll one page at a time, and I'm constantly jumping between 3 browsers, it would be nice to be able to scroll a full page at a time in Safari, just like I can in Firefox. Thanks.

  • Is there any way to get the files from other computer ?

    Hai all,
    I have 2 computers connected. I know the IP address of other computer. Is there any way to get the files from other computer. (for e.g. I want to get the files from specific folder. In Java netwroking is it possible? (Any programs)
    regards,
    Namanc

    Bro Take it easy.
    Think you need to send a Image file named ("abc.gif")
    now develop a server using ServerSocket and connect it in local IP and any PORT
    For example i think ur server is connected in "localhost" and 9000 port.
    Now make ur server educated using some commands.
    For example:
    FileName: <File Name String>
    [Means new file is sending by connected client]
    FileSize: <File size long or int value>
    [ So that ur server can determind about the total length of sender file]
    DataModeOpen
    [Now your client will send its image data, this command means your client software is sending data]
    fjadlkfjaofaijojfwoeiurfodkjflsajlfksa
    l23j4lj23lkjlasjfoq23j4rokjelfkjasldkf
    2o3j4lk2j3ljslakdjf2l3j4 l23kjlk23k4j
    DataModeClose
    [Means file sending finished]
    Close
    [Means your client connection is closed]
    Now develop a client supporting this command.
    For example(Server):
    String getFileName=null;
    long getFileSize=0;
    public handleCommand(String getCmd) {
        if(getCmd.startsWith("FileName")) {
                String[] splitData=getCmd.split(":");
                this.getFileName=   splitData[1];
                outPutStream.writeBytes("+OK");
        } else if(getCmd.startsWith("FileSize")) {
                String[] splitData=getCmd.split(":");
                this.getFileSize=Long.parseLong(splitData[1]);
                outPutStream.writeBytes("+OK");
        } else if(getCmd.startsWith("DataModeOpen")) {
               //data mode open so receive data
              receiveData();
              outPutStream.writeBytes("+OK");
        } else if(getCmd.startsWith("DataModeClose")) {
              //close client socket
             getClientSocket.close();
    }For client:
    DataInputStream dataIn=null;
    BufferedOutputStream bout=null;
    public sendFile(bytes[] getBytes) {
            //if ok found then do other or show error message
        if(sendCmd("FileName:"+getFileName)) {
            if(sendCmd("FileSize:"+getFileSize)) {
                if(sendCmd("DataModeOpen")) {
                   bout.write(getBytes);
                } else {
                   showError(3);
            } else {
                   showError(2);
       } else {
            showError(1);
    }i think it will help u

  • I have downloaded a Audio Book from Itunes Store, but rencently i have had to reinstall windows, is there any way to re-download the audio book from Itunes, i know that the audio books are one time downloads, but is there any way to get the audio book

    I have downloaded a Audio Book from Itunes Store, but rencently i have had to reinstall windows, is there any way to re-download the audio book from Itunes, i know that the audio books are one time downloads, but is there any way to get the audio book back as i have already paid for it once and i would not like to pay for it twice.

    If you haven't got a backup copy and if it's still in the store then you can try contacting iTunes support and see if they will grant you a re-download (there is no guarantee that they will) : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page

Maybe you are looking for

  • Recursion in a jsp page

    I can't figure out where to put a method in a jsp page so that I can call it recursively. Tomcat keeps returning "Not expecting variable declaration here and pointing to the "private void methodname(..){" line. I know it probably something basic but

  • Code Generation Using Annotation Processing

    I'm trying to figure out how to do something like thus: Given this source file with the following custom annotation: @Composite(interfaces=Mammal.class) public class Dog implements IComposite };I want to create an annotation processor that inserts a

  • Can I move nodes in a jTree without the mouse?

    I want to move nodes in a jTree as if I was dragging and dropping but I don�t want to use the mouse. Is this possible and how.

  • Tabular form Update Error,"Current version of data in database has changed

    I'm getting an error when updating a Apex Tabular form. It's complaining that the row id's are out-of-sync. The error reads,' Current version of data in database has changed since user initiated update process. current row version identifier = "56DW5

  • Using iPhone in the Cayman islands and British Virgin Islands

    Have US iPhone with US sim card with AT&T prepaid Gophone plan with roam facility. Travelling abroad. Can I use it in the Cayman and British Virgin Islands? Many thanks in advance.