Obtain string value from structure

I need to the get the file name string, so I can add it to the file validations

Is there a way I can do regex or string_split to get the content on file name?


{"file_date":["2019-10-30T13:51:05Z"],"file_name":["Teste_Excel.csv"],"file_size":["693"]}

Hi Lucas,


Yes, you can use String_Split. Do you know what you need todo?

Regards,
Nuno Verdasca

String_Split receives a string, and a separator, and returns a LIST of strings, that represent the strings after the separators are applied.

You find a description of it in the Text API.

String_Split

Splits a string into individual elements delimited by any of the characters in Delimiters.

Inputs

Text
Type: Text. Mandatory.
Text to be splitted into individual strings.
Delimiters
Type: Text. Mandatory.
Contains all the characters that should be considered as separators.

Outputs

List
Type: RecordList of Text.
List of strings that results from splitting the original Text.

So, it returns a list. Usually this means that you need to store or process this list in the LOGIC, rather than in the interface, as in the interface you would not be able to use the full list, but only a single element. 

Than you can access the String_Split.List after it.


P.S. If the string contains "new lines" as separator, you probably wants to pass NewLine() as value for the Delimeters argument. (Didn't tested, could also be possible with "\n"...)


If you want ALL strings, you have to call it from the Logic. The String_Split returns a LIST, that you can use the way you need it. You can store it in a local list and show it, or process it and put in the result of an aggregate, for example.


Extra Information:

  1. If you want to use this list directly as the source of a List Record or Table Record, you can.
    It will be something like this:
    1. String_Split(your string here).List
  2. Probably it is returning a single line because your separator is wrong...



Hope this helps.
Cheers,

Nuno Verdasca

but I need to get only the content of file name

{"file_date":["2019-10-30T13:51:05Z"],"file_name":["Teste_Excel.csv"],"file_size":["693"]}

Hi Lucas,

String_Split

Substr

Yes as Nuno said you can you use String_Split and if you want to get the filename you need to use substr to get the specific filename that you want. Kindly refer link above for the documentation.


Kindly mark this as solution if its solve your problem.


Best Regards,

Karl Bernardo


Karl Jarobe Bernardo wrote:

Hi Lucas,

String_Split

Substr

Yes as Nuno said you can you use String_Split and if you want to get the filename you need to use substr to get the specific filename that you want. Kindly refer link above for the documentation.


Kindly mark this as solution if its solve your problem.


Best Regards,

Karl Bernardo



I can use substring because the length may change, is there some else like regex?

Hi Lucas,

Try using the Regex_Search function with this pattern:

file_name:\[(.*?)\"\]

Hi Lucas,

Where did you get that string? Isn't that a JSON? If the format is always the same you can just use JSON Deserialize.

Regards,

Marcelo

Marcelo Ferreira wrote:

Hi Lucas,

Where did you get that string? Isn't that a JSON? If the format is always the same you can just use JSON Deserialize.

Regards,

Marcelo


The format is always the same but I nedd the name which is one of the content

Bruno Marques wrote:

Hi Lucas,

Try using the Regex_Search function with this pattern:

file_name:\[(.*?)\"\]


Regex_search is expecting a String input and this itsn´t  allowed

Solution

Hi Lucas,


Hope this helps this will do the trick.


I created a simple server action

I use String_Split and passed a string for example 

{"file_date":["2019-10-30T13:51:05Z"],"file_name":["Teste_Excel.csv"],"file_size":["693"]}


Since you will be using comma "," as you delimiter you will get a list of text 


Index 0 = "file_date":["2019-10-30T13:51:05Z"]

Index 1 = "file_name":["Teste_Excel.csv"]

Index 2 = "file_size":["693"]}


and then after you split the string now you will use substring to get the specific file name.



Substr(string, start index, length)

start index = 12  length of this will not change

"file_name":[


length = length of the string - 1 - start index that's why it is - 13 


this will work even if length is changing


Cheers,

Regards,


Karl Bernardo


Solution

Hi Lucas,

Since the format is always the same and looks like a JSON can't you deserialize it to a structure with the same format? and than access the filename attribute of that structure.

Regards,

Marcelo

Hi Lucas,

I did a small example of how to do this and is a lot better that using string_split. Look into the attachment.

Regards,

Marcelo

Karl Jarobe Bernardo wrote:

Hi Lucas,


Hope this helps this will do the trick.


I created a simple server action

I use String_Split and passed a string for example 

{"file_date":["2019-10-30T13:51:05Z"],"file_name":["Teste_Excel.csv"],"file_size":["693"]}


Since you will be using comma "," as you delimiter you will get a list of text 


Index 0 = "file_date":["2019-10-30T13:51:05Z"]

Index 1 = "file_name":["Teste_Excel.csv"]

Index 2 = "file_size":["693"]}


and then after you split the string now you will use substring to get the specific file name.



Substr(string, start index, length)

start index = 12  length of this will not change

"file_name":[


length = length of the string - 1 - start index that's why it is - 13 


this will work even if length is changing


Cheers,

Regards,


Karl Bernardo



ok, what about the file size it´s content can change, will it work?

lucas ferreira wrote:

Karl Jarobe Bernardo wrote:

Hi Lucas,


Hope this helps this will do the trick.


I created a simple server action

I use String_Split and passed a string for example 

{"file_date":["2019-10-30T13:51:05Z"],"file_name":["Teste_Excel.csv"],"file_size":["693"]}


Since you will be using comma "," as you delimiter you will get a list of text 


Index 0 = "file_date":["2019-10-30T13:51:05Z"]

Index 1 = "file_name":["Teste_Excel.csv"]

Index 2 = "file_size":["693"]}


and then after you split the string now you will use substring to get the specific file name.



Substr(string, start index, length)

start index = 12  length of this will not change

"file_name":[


length = length of the string - 1 - start index that's why it is - 13 


this will work even if length is changing


Cheers,

Regards,


Karl Bernardo



ok, what about the file size it´s content can change, will it work?

yes of course.


Substr(String_split.List[2].Text.Value, 13, Length(String_Split.List[2].Text.Value - 15)


Substr(string, start index, length)

start index = 13

"file_size":[


length = length of the string - 2 - start index (13) 


Kindly mark this as answer if this will resolve your problem


Thanks.


Cheers!

marked as awnser karl

lucas ferreira wrote:

marked as awnser karl

I really appreciate it lucas I just want you to know that it's my first mark as answer and I got the badge I am very glad that I did help you.


Thanks.


Best Regards,

Karl Bernardo