I like to understand how you can set Ens.StreamConainer to a string value. I just see a class for setting the OriginalFilename but nothing for setting the body.
s pRequest = ##class(Ens.StreamContainer).%New()
s pRequest.OriginalFilename = "Test"
d pRequest.Stream.Read(hl7) //Error Out
d pRequest.StreamSet(hl7) //Getting empty string
If hl7 is a stream:
s pRequest = ##class(Ens.StreamContainer).%New(hl7)
It hl7 is a string:
s pStream = ##class(%Stream.GlobalCharacter).%New()
do pStream.Write(hl7)
s pRequest = ##class(Ens.StreamContainer).%New(pStream)
Some code advice:
d pRequest.Stream.Read(hl7) //Error Out
Read reads from stream, and Write writes to stream.
d pRequest.StreamSet(hl7) //Getting empty string
It is a setter method for Stream property. There's no need to call it directly, just set the property.
Related
I have to check runtime Type of value for this I am using :-
for Example:-
String a = "abc";
int b = 123;
var c = "123"; //this is int value but because of this double quotes is represent as a String
a.runtimeType == String //true
b.runtimeType == int // true
c.runtimeType == String //true
c.runtimeType == int //false
a = "abc" // okay
b = 123 //okay
c = "123" //is issue
now I have to call a api with only String body in this case :-
this c is called the API because is String but i know this is a int value which is present as a String, so I have to stop this.
How can I check this??
when I am using try catch so my program is stopped because of FormatException error.
Note:- I don't know the real value of C, may be its "123" or "65dev" or "strjf" this value is changed every time.
and if i am parsing this in int to this return an error in many case.
Ok i understood that you want to pass "123" by checking and if it is int you are passing it , My question is what you will do if it is "123fe" you are going to pass as string? or you will pass nothing.
I don't know how you're passing it to API but if you wanna pass integer value from string quoted variable, you can parse/convert to integer like this.
int.parse(c);
either you can pass it directly or you can store in another variable and pass that variable.
Alternatively if you've int value and to have to pass it as a string, simply parse like this
integerValue.toString();
according to your code
b.toString();
Edit
String a = '20';
String b = 'a20';
try{
int check = int.parse(a);
//call your api inside try then inside if
if(check.runtimeType == int){
print('parsed $check');
}
}
catch(e){
print('not parsed ');
//handle your error
throw(e);
}
This will definitely help you!
String name = "5Syed8Ibrahim";
final RegExp nameRegExp = RegExp(r'^[a-zA-Z ][a-zA-Z ]*[a-zA-Z ]$');
print(nameRegExp.hasMatch(name));
//output false
name = "syed ibrahim";
print(nameRegExp.hasMatch(name));
//output true
Just check the output and based on that boolean value invoke api call
I hope it will done the work
Trying to pass a string to URLComponents's percentEncodedPath crashes the app if the string is not a valid percent encoded path.
Is there a way to tell if the string is a valid percent encoded path before I set it? I am having trouble figuring this one out.
var urlComponents = URLComponents()
urlComponents.percentEncodedPath = "/some failing path/" // <- This crashes
You can do something like this:
extension String {
var isPercentEncoded: Bool {
let decoded = self.removingPercentEncoding
return decoded != nil && decoded != self
}
}
The rationale:
If the String is URL-encoded, removingPercentEncoding will decode it, and hence decoded will be different from self
If the String contains a percent (but is not URL-Encoded), removingPercentEncoding will fail, and hence decoded will be nil
Otherwise string will remain unmodified
Example:
let failingPath = "/some failing path/"
let succeedingPath = "%2Fsome+succeeding+path%2F"
let doubleEncoded = "%252Fsome%2Bfailing%2Bpath%252F"
let withPercent = "a%b"
failingPath.isPercentEncoded // returns false
succeedingPath.isPercentEncoded // returns true
doubleEncoded.isPercentEncoded // returns true
withPercent.isPercentEncoded // returns false
One disadvantage is that you are on a mercy of removingPercentEncoding and also this is a "mechanical" interpretation of the string, which may not take into account the implementation intent. For example a%20b will be interpreted as URL-encoded. But what if your app expects that string as a decoded one (and so it needs to be encoded further)?
I want to extract the value of id in the stanza tag.
The stanza tag is:
[<stanza-id xmlns="urn:xmpp:sid:0" by="f.talebi#wepod.ir" id="1531235744929009"></stanza-id>]
This is a part of message received from Xmpp server. I need to extract "1531235744929009" value. Therefore, I wrote this:
var stanza = message.elements(forName: "stanza-id")
print(stanza)
var id = stanza.first?.attributes
if let attributes = stanza.first?.attributes {
let lastItem = attributes.last
if let stanzaID = lastItem?.stringValue {
print("stanzaID = \(stanzaID)")
}
}
This code works correctly, but its not a clean code. especially where I wrote this line lastItem = attributes.last because if the order changes this won't work.
just use stanza.attributed(forName: String)
//main code
list ls = memberMap.get(Rz.Roles__c);
String JSONString = JSON.serialize(ls);
//Debug code
[{"attributes":{"type":"Work_Team_Member__c","url":"/services/data/v42.0/sobjects/Work_Team_Member__c/a81W00000008gIsIAI"},"Id":"a81W00000008gIsIAI","Member_Employee_ID__c":"63","Member_Name__c":"Test1","Member_Role__c":"Account Representative – General (Secondary)","Work_Team_Master__c":"a80W00000009DodIAE"}]
I try ILNumerics.IO.HDF5 and can not read the following data:
Variable length strings in Datasets and Attributes.
Datasets with variable length arrays. Each cell contain a array of numbers, which are histograms.
Compound data, ie. Datasets with structs containing some numbers.
In HDFView 2.10.1 I can read this data:
https://anonfiles.com/file/13756916026cafc4e4ec7c333f235bda
How can I use ILNumerics.IO.HDF5 with this data?
I found an other post with suggestion to read string as char.
But with the variable length string an exception is thrown: "Error reading data from the attribute!"
var file = new H5File("test.h5");
H5Dataset ds1 = file.First<H5Dataset>("Wind");
var att = ds1.Attributes["Aggregator"];
var value = att.Get<char>();
Could you provide more info on how you write the string attributes and what exactly is the issue. When you say 'can not read',Do you get a null return value or do you get an exception.
I write strings as attributes in my application and it works fine. I am guessing there could be a problem in the way you write the string. As per Haymo's suggestion, I convert the string into char array and write as attribute. Here is the sample code
private ILRetArray<Char> ConvertStringToArray(string str)
{
using (ILScope.Enter())
{
ILArray<Char> A = ILMath.array<Char>(' ', 1, str.Length);
for (int i = 0; i < str.Length; i++)
{
A.SetValue(str[i], 0, i);
}
return A;
}
}
Test Case :
using (var file = new H5File("testwrite.h5"))
{
var ds = new H5Dataset("data", ILMath.rand(10,10));
file.Add(ds);
string teststr = "Test string";
ILArray<char> charStr = ConvertStringToArray(mystr);
ds.Attributes.Add(new H5Attribute("mystring",charStr));
//Read back the dataset and its attributes
var group = file.Find<H5Dataset>("data").First();
ILArray<Char> storedData = group.Attributes["mystring"].Get<Char>();
}