Home > Net >  How to remove first part of string so I can decode it. flutter/dart
How to remove first part of string so I can decode it. flutter/dart

Time:08-01

I'm getting bytes property from api as a string but it has prefix and it looks like this: data:application/octet-stream;base64,JVBERi0xLjcNJeLjz9MNCjEgMCBvYmoNPDwv.... So my question is how can i remove this part data:application/octet-stream;base64, from string so I can decode the rest of same string.

CodePudding user response:

Simply use a .split() method.

  final str = "data:application/octet-stream;base64,JVBERi0xLjcNJeLjz9MNCjEgMCBvYmoNPDwv0w";
  final desiredStr = str.split(',')[1];

CodePudding user response:

Another way to do it is like:

final str = "data:application/octet-stream;base64,JVBERi0xLjcNJeLjz9MNCjEgMCBvYmoNPDwv0w";
final desiredStr = str.substring(str.indexOf(',')   1);

CodePudding user response:

Another way to do it is Like :

final secondHalf = str!.split(',').last; /// Answer : JVBERi0xLjcNJeLjz9MNCjEgMCBvYmoNPDwv0w

final firstHald = str!.split(',').first;  /// Answer : data:application/octet-stream;base64

CodePudding user response:

I think data:application/octet-stream;base64, is base64 string of your any picture so simply you can use split method with split("data:application/octet-stream;base64,") so it will cut down the string in two part and i had a experience with bas64 string data:application/octet-stream;base64, is same every time so you can hard code it use use it like

final str = "data:application/octet-stream;base64,JVBERi0xLjcNJeLjz9MNCjEgMCBvYmoNPDwv0w".split("data:application/octet-stream;base64,")[1];

  • Related