simple text to the acceptability of url?

I want to convert the spaces containing simple text, url, so that he can bhi added to the browser

as I am adding text to share the Tweets: TWITTER_URL + "Hello this is sample text."

But how can I convert the string in characters acceptable browser?

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;

/**
 * Adapted from J2SE java.net.URLEncoder.
 */
public class URLEncoder {

  public static String encode(String s, String enc)
    throws UnsupportedEncodingException {

    boolean needToChange = false;
    boolean wroteUnencodedChar = false;
    int maxBytesPerChar = 10; // rather arbitrary limit, but safe for now
      StringBuffer out = new StringBuffer(s.length());
    ByteArrayOutputStream buf = new ByteArrayOutputStream(maxBytesPerChar);

    OutputStreamWriter writer = new OutputStreamWriter(buf, enc);

    for (int i = 0; i < s.length(); i++) {
        int c = (int) s.charAt(i);
        //System.out.println("Examining character: " + c);
        if (dontNeedEncoding(c)) {
        if (c == ' ') {
            c = '+';
            needToChange = true;
        }
        //System.out.println("Storing: " + c);
        out.append((char)c);
        wroteUnencodedChar = true;
        } else {
        // convert to external encoding before hex conversion
        try {
            if (wroteUnencodedChar) { // Fix for 4407610
                writer = new OutputStreamWriter(buf, enc);
            wroteUnencodedChar = false;
            }
            writer.write(c);
            /*
             * If this character represents the start of a Unicode
             * surrogate pair, then pass in two characters. It's not
             * clear what should be done if a bytes reserved in the
             * surrogate pairs range occurs outside of a legal
             * surrogate pair. For now, just treat it as if it were
             * any other character.
             */
            if (c >= 0xD800 && c <= 0xDBFF) {
            /*
              System.out.println(Integer.toHexString(c)
              + " is high surrogate");
            */
            if ( (i+1) < s.length()) {
                int d = (int) s.charAt(i+1);
                /*
                  System.out.println("\tExamining "
                  + Integer.toHexString(d));
                */
                if (d >= 0xDC00 && d <= 0xDFFF) {
                /*
                  System.out.println("\t"
                  + Integer.toHexString(d)
                  + " is low surrogate");
                */
                writer.write(d);
                i++;
                }
            }
            }
            writer.flush();
        } catch(IOException e) {
            buf.reset();
            continue;
        }
        byte[] ba = buf.toByteArray();
        for (int j = 0; j < ba.length; j++) {
            out.append('%');
            char ch = CCharacter.forDigit((ba[j] >> 4) & 0xF, 16);
            // converting to use uppercase letter as part of
            // the hex value if ch is a letter.
//            if (Character.isLetter(ch)) {
//            ch -= caseDiff;
//            }
            out.append(ch);
            ch = CCharacter.forDigit(ba[j] & 0xF, 16);
//            if (Character.isLetter(ch)) {
//            ch -= caseDiff;
//            }
            out.append(ch);
        }
        buf.reset();
        needToChange = true;
        }
    }

    return (needToChange? out.toString() : s);
  }

 static class CCharacter {
    public static char forDigit(int digit, int radix) {
      if ((digit >= radix) || (digit < 0)) {
          return '\0';
      }
      if ((radix < Character.MIN_RADIX) || (radix > Character.MAX_RADIX)) {
          return '\0';
      }
      if (digit < 10) {
          return (char)('0' + digit);
      }
      return (char)('a' - 10 + digit);
  }
  }
  public static boolean dontNeedEncoding(int ch){
    int len = _dontNeedEncoding.length();
    boolean en = false;
    for(int i =0;i< len;i++){
      if(_dontNeedEncoding.charAt(i) == ch)
      {
        en = true;
        break;
      }
    }

    return en;
  }
  //private static final int caseDiff = ('a' - 'A');
  private static String _dontNeedEncoding = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -_.*";

  /**
   * @param args  test string
   */
  public static void main(String[] args) {
    String s = args[0];
    try {
      System.out.println(encode(s,"UTF-8"));
    } catch (UnsupportedEncodingException e) {
    }
  }
}

Tags: BlackBerry Developers

Similar Questions

  • Beyond a simple text on the Clipboard in the text using the key field

    Dears

    You would tell me is it possible of past a simple text on the Clipboard into a field of text using button with javascript or something else?

    What is my problem?

    I have prepared a simple form using adobe acrobat dc. This form will be used in the local network. so, we can open the form of google chrome. There is a large text field in this form and we have passed the text to the Clipboard in there.

    normal, when we are using adobe acrobat to open the form, it is easy to right click and select "PASTE". but we need open the form using google chrome. in this case, no item to paste from the Clipboard.

    Please help me.

    Concerning

    In General, no, it's not possible.

    However, if you apply a certain change in the registry then work could . I told you how do it here: paste it from the Clipboard text box in form

  • Text of the link to URL

    Hi all:

    I created a text to post a link to another page in a flash site. If you go to this address, North East Building , and then click the PORTFOLIO link.

    With the menu that descends, I linked to another page html, however, link the LETTERS of the TEXT links and not the word in his together, making it difficult to click on.

    I tried to add a box of rectangle on a different layer inside the button in the part with to solve this question though, I can't apply actionscript to and it's fustrating me no end.

    I don't know what I have to do to make it work the way I want.

    Whoo Hoooo!

    It worked... Thank you so much Ned so that little advice that I can't find anywhere online or in any tutorial.

  • Download Simple text file from internet URL (base CVI)

    I am trying to download a simple textfile locally on the computer using CVI (basic package).

    I've seen many examples of Web browser and other programs of crazy whistle.  All I want to do is travel to a URL and download the file text in the background.  I tried to use the IWebBrowser program but could not figure out how to save the file to my output name specified without user intervention.

    To be even more precise, here is a sample URL.  I want to save this file as yuma.txt in my working directory.  No prompt or anything.

    http://www.NAVCEN.USCG.gov/archives/GPS/2009/ALMANACS/Yuma/001.Alm

    to be registered as yuma.txt

    Be specific about what instruments or dll to use and where to get them.

    Thank you very much!

    After installing the program wget of GnuWin, I could simply extract files, wget.exe and .dll to the bin directory and get the program to run on another computer.  So, it would be the ultimate solution.

    http://GnuWin32.sourceforge.NET/packages/wget.htm

    For this reason, the only losses are not have a preset file that comes with the program that is installed in the default path (which you can ignore any entry in the same command line arguments) and have the register of the installedpath.

    If this solution seems to work!  Thank you

  • Pass a variable to a text entry field in a URL (was: I feel like it should be simple but)

    I think it should be simple, but I'm having a hard time finding how to pass a variable to a text entry field in a URL. I have a text input field ("enter your postal code') and a button that says 'Go '. When the user enters their zip and hit 'Go', I need the postcode, they came to pass in a URL to a new Web site so that they can see the offers in their region. This is a Flash 300 x 250 banner. Can someone help me?

    I can download my FLA somewhere and link to it if needed!

    Click on the frame that contains your go button and your textfield and paste Panel actions:

    go.addEventListener (MouseEvent.CLICK, f);

    function f(e:MouseEvent):void {}

    navigateToURL (new URLRequest ("http://namebrandinsurance.com/auto/newResults.php?zip=" + zip.text + "& submit = submit"));

    }

  • After a recently added update Firefox ' VISIT: url' / ' search: text "as the first result... can remove you that?

    Its quite annoying. It will simply display the URL for previously visited sites... but if I wanted to look for something... I would simply enter the text in the address bar now she suggested this little annoying thing that says to go directly to the URL.

    I have not controlled search suggestions and he always does.

    See the solution chosen to
    https://support.Mozilla.org/en-us/questions/1099785

  • I see that a small part of the text in the url bar, the rest is cut off.

    Recently, my url bar displays only the first handful of letters in my url. If I use the arrow keys, I can see all the text is there, and hit enter brings to the top of the right-hand page, so is not cut the text, just the screen. About the first 15% of the present url bar text, while the bar remains is just gray. I am currently on 16.0.2.

    This may be a problem with AuthenTec TrueSuite.

    See:

  • How to disable the placeholder text in the URL from the navigation bar and search fields?

    Everytime I open a new tab (often, the homepage is set to blank) I watch 'Go to site' in the navigation bar. The search field shows the name of the active search engine until the text is registration. All I want is to be able to do is disable the placeholder text, showing the two fields as white.

    Add code to the file userChrome.css below default @namespace.

    Customization files (interface) userChrome.css and userContent.css (Web sites) are located in the chrome folder in the user profile folder.

    @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* only needed once */
    
    *|*.textbox-input:-moz-placeholder { color:transparent !important; }
    *|*.textbox-input:-moz-placeholder:hover { color:graytext !important; }

    Use in Firefox 19 +:

    @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* only needed once */
    
    *|*.textbox-input::-moz-placeholder { color:transparent !important; }
    *|*.textbox-input:hover::-moz-placeholder { color:black !important; }
  • Sequence step results in the report in Simple text format

    I use Teststand 2012 and that you have installed the plugin from model simple text report.

    My main test sequence called a number of subsequences that contain the test steps and contain also several subsequences. A number of the subsequences is only stocks. My test result file contains all the results of measures of test as expected, but it also contains a line of output for each call of sequences - makes it difficult to see the results that count. I would only record the test steps.

    Looking at the code SimpleTextReport.dll in CVI I see it is stepping into the results and updated list in the form of each line (I changed some of the formatting). Is this the right place to filter the levels of appeal of sequence or can I stop the call sequence steps to be added to the list of results?

    You can put it in the sequential model. Just use ProcessModelPostResultListEntry with the same code. If it's in the template, you won't need it in other files. In addition, he is probably already stuff in the model. You'll have to code around it. This is how they do it on the fly.

  • configuration of the plugin simple text report

    I am updating a project of Teststand 4.2 for 2012. The original was a text via a report updated the sequential model and ICB code. I have trying to find current best practices to achieve a similar report.

    I installed the plugin to report simple text example but can find no documentation on how to configure it.

    The example works fine, but the columns have no limits or the measured value and have other items that I didn't need.

    Looking through the code I can see these are defined in the settings of the plugin, but I do not see where in my project to put.

    I'll also have to configure the report header and the name of the file.

    David

    What exactly do you mean by "key values"? Are you referring to the Key property in the NI_SimpleTextReport_CVI.seq?

    In order to get the type of comparison of a numerical limit test, for example, you can use an Expression like this post:

    Locals.ComparisonType = Step.Comp

    This would amount to "FROZEN".

    Regarding the addition of the results of the report, the key values are a string of research compared to a result object. In this case, you can add what you want to log on to the other results of this approach. Then, you can add a new column to the report in the NI_SimpleTextReport_CVI.seq file and the value of the key:

    AdditionalResults ["NameOfAdditonalResult"]

  • The context of invocation. Simple text sharing problem

    Hello

    I would like to have an option of sharing simple text on my request. To do this, I use this code in my. QML file:

    ActionItem {
         attachedObjects: [
              Invocation {
                   id: invoke
                   query: InvokeQuery {
                        id: invokeQuery
                        mimeType: "text/plain"
                        data: "This is a text text"
                   }
              }
         ]
    
         title: qsTr("Share")
         imageSource: "asset:///images/share.png"
         ActionBar.placement: ActionBarPlacement.OnBar
         onTriggered: {
              invoke.trigger("bb.action.SHARE")
         }
    }
    

    With the above text, I can see the hardcoded text appear in all applications that I can share for (bold line), however, if I use the following line to change the text dynamically to the current item of the list instead I get nothing. No text is common to all:

    data: ListItemData.description
    

    Do you have someone was able to share a dynamic text?

    Thank you

    Well, I managed to find a solution, but I had to use C++ instead of QML. You have here, just in case some of you have the same problem:

    void MyApp::share(QString name, QString surname, QString age)
    {
         printf("Share invoked");
    
         m_pInvocation = Invocation::create(
              InvokeQuery::create()
               .parent(this)
               .mimeType("text/plain")
               .data(name.toUtf8() + surname.toUtf8() + age.toUtf8()));
          QObject::connect(m_pInvocation, SIGNAL(armed()),
            this, SLOT(onArmed()));
          QObject::connect(m_pInvocation, SIGNAL(finished()),
            m_pInvocation, SLOT(deleteLater()));
    }
    
    // Declare the following method as SLOT on your .hpp file
    void MyApp::onArmed() {
        m_pInvocation->trigger("bb.action.SHARE");
    }
    
  • former Illustrator files will open only in the form of Simple Text Documents

    I went back to an old project Adobe Illustrator I have not opened for years but suddenly need to recovery. To my horror, I discovered that I can not open ONE of these old files HAVE. In the finder, each of these files is shown not as an .ai file, but as a "simple text document. When opening, it does is display a text code page, not my graphics HAVE. I'm currently running AI CS5 on Mac OSX 10.8.5. I would greatly appreciate all useful advice - what someone might have on this subject. Y at - it HAVE a plug-in available for update old files? No matter what?

    Thanks for your help!

    Frank Gresham

    Hi everyone who responded, or interested:

    I think I found the fix, courtesy of the Mac guru at the University where I teach. If I just add the suffix .ai on behalf of all of my files, they instantly change to read Adobe Illustrator files! Couldn't be simpler, although it raises a question. These files will open very well without needing to be done with the file at the end of each title designations. Now, suddenly, they need ".ai" after them to open properly. Well. At least, I have a solution to this problem.  Thanks for all the good advice!

    Frank G.

  • I have a form in which the text area can be developed to accept more text, but the text does not appear on the printed copy.  How can I get the text to print?

    I have a form in which the text area can be developed to accept more text, but the text does not appear on the printed copy.  How can I get the text to print?

    Hi robinm6200,

    Make sure that you have selected 'Document and annotations' under 'Comments and forms' when printing.

    Kind regards

    Nicos

  • Simple question - alternative text of the attribute in the same Word document

    Ok. I am having a brain freeze and cannot find the answer in the help of the OPA. Simple question.

    Is there a simple way to alias an attribute for use in Word?

    For example, the following two conclusions create 2 attributes where I want only 1 attribute.

    annual percentage rate = 6
    APR = annual percentage rate

    Is there a configuration option or something to alias APR as the rate of annual percentage for use in Word? I want to use in the same Word document. Something in my head tells me that I have seen that once before, but all of a sudden, I've got a brain freeze.

    Sorry for such a simple question, but sometimes I get too deep into the weeds.

    Hi Paul,.

    You may think the style of the legend of OPA. In the 2007 OPM Office Ribbon it's called legend of the table, but I think that it works with the rules of non-table in Word as well - it is certainly used to.

    It's a style of OPA rule which can be used when you want to refer to an abridged version of an attribute, for example "APR" rather than "the annual percentage rate. According to me, that it applies only to the immediately lower rule where it has been defined in the doc and the doc not complete.

    I did a quick search in the help of the OPM and found references to the style of legend, but I have not found a description of the functionality (search is not too good if).

    Essentially how it works...

    Above the rule to write the version abridged, then the word "is", then the text of the full attribute, for example

    APR is the annual percentage rate
    

    Side note: I have always "BOLD" the "is" in the callout line. It is not necessary, but I want to do it because it makes it more clear at a glance what part is the shorthand and which part is the text of the full attribute.

    Then apply the style of the legend of the table to the line, then put your Word table or the ordinary rule underneath, for example

    [legend]APR is the annual percentage rate
    
    the result = APR * 10 
    

    I use this feature occasionally. Usually it is when I have calculations in Word tables and I'm trying to make the more readable left column, for example using something "APR" in the formula so that it does not take much space.

    See you soon,.
    Jasmine

  • Move URL in the link text or the text at the end of the story. Also: tables

    Hello everyone

    I am currently working on a script which translates by Textile Markup InDesign-formatted text. It worked well for the most part, because it is really hard to do by FindChangeByList. However, some things are a bit more complicated than the others. Namely the URL in the text. Textile, all URLs are so similar. Let's say I want to make a link to Google. So I type this: 'Google':http://www.google.com happen Google. I can isolate the word and delete the URL of ["------"](.+?) [\\\"]:\\?\\S+ and substituting $1.] So far so good.

    However!

    It would be great, if the URLS are still in the text. Then I would be to have as follows: Google or that the word Google (or any what $1, really) is found in the text, then the link is added at the end of the text as a sort of "Sources"-paragraph thing. ". How is that possible? I can do by FindChangeByList? Because that would be cool, because then I would just need to run a script.

    And here's a general question: How can I translate Textile-Tables in InDesign Tables formatting?

    For reference, it would be a table with a row of a header.

    |_. name | _. age | _. sex |

    | Joan | 24. e _

    | Archie | 29. m |

    | Bella | 45. e _

    Is this possible?

    Thank you very much for your help!

    Hello

    Ok. If you can assume that $2, it's exactly a word ==> we could edit it above like this:

    //...
    mSource = mDoc.hyperlinkTextSources.add(mText[0].words.itemByRange(0,-2).texts[0]);
    mDest = mDoc.hyperlinkURLDestinations.add(mText[0].words[-1].contents);
    //...
    

    Jarek

Maybe you are looking for

  • Portege M750 and Win8.1 Pro - the tablet buttons do not work

    Hello I have problems to install the tablet buttons in WINDOWS Pro 8.1. Everything else works perfectly. In Windows 8 Pro this button worked fine, but now, after clean installation of Windows Pro 8.1 two buttons do not work. The buttons are the Toshi

  • Newsgroup appears not

    Not able to see my groups .please fix ASAP

  • HP Mini 1000: reset password for the HP Mini 1000

    Impossible to go beyond wood entry password. Error code is CNU91410dv

  • launch of the Explorer error lvproj

    Hello I use Vista SP1 32-bit 10 LV and it works OK for a month. I was doing some storage project / renaming etc but when I tried to restart using a window of the Explorer and double click on the .lvproj file I dialog "Windows cannot find ' c:\.  (my

  • Gateway NE56R10u no video.

    How can I force video port monitor when starting, or is - ext this automatic when the cable is plugged? Laptop seems to start properly, but both screen and external monitor showing not any video at all. Possible bad mother?