logo
down
shadow

Read UTF-8 encoded file that includes 4-byte encodings into Excel


Read UTF-8 encoded file that includes 4-byte encodings into Excel

By : Rian O'Hanlon
Date : November 20 2020, 03:01 PM
this will help ADODB.Stream.ReadText documentation explains an efficiency problem and proposes reading fewer bytes at a time to mitigate it.
So,
code :
  Dim FileStream As Stream: Set FileStream = CreateObject("ADODB.Stream")

  With FileStream
    .Charset = "utf-8"
    .Open
    .LoadFromFile "C:\Users\Tom\Downloads\examples.json"

    Dim FileBodyADO As String: FileBodyADO = ""
    While Not .EOS
        FileBodyADO = FileBodyADO & .ReadText(128 * 1024&)
    Wend
    Debug.Print Len(FileBodyADO)
    Debug.Assert Len(FileBodyADO) = 92630322
    .Close
  End With

  Set FileStream = Nothing
File.ReadAllText(@"C:\Users\Tom\Downloads\examples.json").Length == 92630322


Share : facebook icon twitter icon
Read an in-memory Excel file (byte array) with ADO.NET?

Read an in-memory Excel file (byte array) with ADO.NET?


By : khaperey
Date : March 29 2020, 07:55 AM
Hope that helps You can't connect if it only exists in memory. OLE is also ruled out (though using Office Automation for a server application is poor design to begin with).
The only way I can think of is to read the binary Excel data yourself - for example use SpreadSheetGear.Net with something like:
code :
SpreadsheetGear.Factory.GetWorkbookSet().Workbooks.OpenFromStream(*stream*);
How to write a generic code to read an html encoded with different encodings?

How to write a generic code to read an html encoded with different encodings?


By : user3305507
Date : March 29 2020, 07:55 AM
Any of those help I'm trying to write a code to read the content of a web page, but I'm not sure of the used encoding in that page, so how can I write a generic code that returns the right string without the strange symbols? The encoding might be ("UTF-8", "windows-1256", ...). I've tried to but the UTF-8 but when the page is encoded with the second mentioned encoding I'm having some strange symbols. , You must examine the response text to check this field:
code :
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
var enc1 = Encoding.GetEncoding("windows-1256");
var enc2 = Encoding.GetEncoding(1256);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var enc1 = Encoding.GetEncoding(response.ContentEncoding);
string Charset = response.CharacterSet;
var enc1 = Encoding.GetEncoding(Charset);
Can two different strings when encoded with different encodings have the same byte sequence?

Can two different strings when encoded with different encodings have the same byte sequence?


By : Chicago9
Date : March 29 2020, 07:55 AM
hope this fix your issue Yes. To take a simple example, the string “¡” (the inverted exclamation mark) encoded as ISO-8859-1 and the string “Ą” (capital A with ogoned) encodes as ISO-8859-2 both become the single-byte sequence A1 (hex). It is more or less obvious that such things happen when using the very simple encodings that map characters to single bytes; otherwise they would not be different encodings. It can surely happen when more complicated encoding schemes are involved, too.
write/read variable byte encoded string representation to/from file in JAVA

write/read variable byte encoded string representation to/from file in JAVA


By : Aji
Date : March 29 2020, 07:55 AM
wish of those help It is solved; I was just not reading the file the right way:below is the right way:
code :
DataInputStream inStream = null; 
inStream = new DataInputStream(new BufferedInputStream(newFileInputStream(file)));

int c = -1;
while((c = inStream.read()) != -1){
    Byte b = new Byte();
    b.readInt(c);
    System.out.println( c +":" + b.toString());
}
6:00000110
184:10111000
133:10000101
13:00001101
12:00001100
177:10110001
int c = -1;
LinkedList<Byte> bytestream = new LinkedList<Byte>();
while((c = inStream.read()) != -1){
    Byte b = new Byte();
    b.readInt(c);
    bytestream.add(b);
}
LinkedList<Integer> numbers = VBEncoder.decode(bytestream);
for(Integer number:numbers) System.out.println(number);
//
//here goes the code of VBEncoder.decode
public static LinkedList<Integer> decode(LinkedList<Byte> code) {
    LinkedList<Integer> numbers = new LinkedList<Integer>();
    int n = 0;
    for (int i = 0; !(code.isEmpty()); i++) {
        Byte b = code.poll(); 
        int bi = b.toInt(); 
        if (bi < 128) {
            n = 128 * n + bi;
        } else { 
            n = 128 * n + (bi - 128);
            numbers.add(n); 
            n = 0; 
        }
    }
    return numbers;
}
824
5
214577
Read JSON data from UTF-8 encoded byte string

Read JSON data from UTF-8 encoded byte string


By : Ørjan Mæhre
Date : March 29 2020, 07:55 AM
I wish this help you You are encoding to JSON then decoding again. SImply not encode, remove the second line:
code :
decodedjson = data.decode('utf-8')
loadedjson = json.loads(decodedjson)
loadedjson = json.loads(data)
>>> data = b'{"Current": 117.42609405517578, "Accelerometer": -5.394751071929932, "SpeedometerKPH": 67.12493133544922, "Ammeter": 117.3575210571289, "Amp": 117.35590362548828, "Acceleration": -0.03285316377878189, "TractiveEffort": -5.394751071929932, "Effort": 48.72163772583008, "RawTargetDistance": 3993.927734375, "TargetDistanceBar": 0.9777777791023254, "TargetDistanceDigits100": -1.0, "TargetDistanceDigits1000": -1.0}'
>>> loadedjson = json.loads(data)
>>> loadedjson['Ammeter']
117.3575210571289
shadow
Privacy Policy - Terms - Contact Us © voile276.org