Frage

i have a variable with persian culture digits like this:
string Value="۱۰۳۶۷۵۱";
i want to convert this digits to English version and save it again in my string like this
Value="1036751";

please help me how can i do this if i can use easy way like culture info instead of switch case

War es hilfreich?

Lösung

You can use the Windows.Globalization.NumberFormatting.DecimalFormatter class to parse the string. This will parse strings in any of the supported numeral systems (as long as it is internally coherent).

Andere Tipps

You can do that with a number of tools. iTextPdfSharp will likely be able to do it. It will amount to opening the document and walking the tree in the catalog that has the bookmarks in it. Their code works fine, but be sure to download the spec so you can understand the structure of the tree. I worked the original version of Acrobat and many of my fellow engineers engineers felt that the bookmark tree was a little over-complicated.

BitMiracle offers similar code. They routinely patrol Stack Overflow, so you might see an answer from them too (HI!) - you can see a sample of their work here for authoring bookmarks.

If you're willing to pay money, this is easy using Atalasoft's DotPdf (disclaimer: I work for Atalasoft and wrote nearly all of DotPdf). In our API, we try to hide the complexity of the structure where possible (for example, if you want to iterate of the chain of chains of actions taken when a bookmark is clicked, it's a foreach instead of a tree walk) and we've wrapped the bookmark tree into standard List<T> collections.

public void WalkBookmarks(Stream pdf)
{
    // open the doc
    PdfDocument doc = new PdfDocument(pdf);
    if (doc.BookmarkTree != null)
    {
         // walk the list of top level bookmarks
         WalkBookmarks(doc.BookmarkTree.Bookmarks, 0);
    }
}

public void WalkBookmarks(PdfBookmarkList list, int depth)
{
    if (list == null) return;
    foreach (PdfBookmark bookmark in list)
    {
        // indent to the depth of the list and write the Text
        // you can also get the color, basic font styling and
        // the action associated with the bookmark
        for (i = 0; i < depth; i++) Console.Write("  ");
        Console.Writeline(bookmark.Text);
        // recurse on any children
        WalkBookmarks(bookmark.Children, depth + 1);
    }
}

PDFs can contain at least three different things which may be called "table of contents":

  1. Document outline (bookmarks), a set of specific PDF structures
  2. List of hyperlinks in the beginning of a document. Each hyperlink leads to a place withing the document
  3. List of text strings where each string names a part of the document and, optionally, specifies on which page this part starts.

I do not know about any out-of-the box or easy to implement solutions for the third case. Other cases are simpler.

For the first case, almost any PDF library will do. @plinth (Hi!) gave at least two solutions for such a case.

For the second case a solution could be implemented using Docotic.Pdf library. Basically, you might try to:

  • enumerate all links in a document
  • find all links that are close to each other (you'll need to build up some heuristics for what to treat as "close")
  • retrieve text from found links

If your case is "list of hyperlinks" then the Extract text from link target sample might give you some clues for a start.

Disclaimer: I work for Bit Miracle, vendor of Docotic.Pdf library.

You'll need to use a pdf-library like pdflib in order to read pdf-files (http://www.pdflib.com/) . That should do the trick, good luck!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top