File Extension in Matlab - file

Is there any way to get extension of a file from its filename ??
The only algo I could develop to do the above task is to find last '.' and rest all string to end..
But not too sure how to get index of final '.' from the given string..
Any new idea or suggestion for the same ??
I'm actually trying to develop a filter which only does processing on all image files rather than other non image file... Is there any other way of doing the same using any inbuilt function ???

Use the built in function "fileparts".

You can use the regexp function with the split parameter
output = regexp(your_string, '\.', 'split')
The output is a cell array that you can pull the value you want out of.
http://www.mathworks.com/help/techdoc/ref/regexp.html

Related

Explode from a txt file

I use explode in my php code to load the strings from a txt file into an array. The strings are loaded into array with no problem, however, the first element has an index 0 but I want it to have an index 1. How do I achieve that?
I appreciate any help cause I've tried so many things and nothing seems to be working and I feel I got stuck.
You can use array_unshift to insert dummy element then remove it using unset as follows :
$ex_array = array("PHP","JAVA","C#","Python", "Javascript", "C");
array_unshift($ex_array,"");
unset($ex_array[0]);

API Gateway pass array of parameters in querystring

I have some issues with passing array of parameters to query string for GET method, for example, /resource&item=1&item=2&item=3.
I have tried to pass parameters separated by commas and by &, it doesn`t work. How to configure API Gateway to do this? Can anyone help me?
Your example was using an ampersand (&) instead of a question mark (?) for separating the query string parameter from the path. I'm assuming that's just a typo.
Try passing the array using json syntax like
/resource?item=['1','2','3']
have you tried this way :
/resource&item[]=1&item[]=2&item[]=3
The way you used would erase the first data by the last data in the url.
What we are doing in our company is to pass data separated by ,. On Backend we explode the parameter and make it array again. I am not sure if there is more better way to do it or not. Let me know if you find any.
like ?items=1,2,3,4
And we get explode items with , through extra code
and get result as [1,2,3,4]

Issue reading .txt file in Matlab. I want to get an array from this file without the unnecessary info it contains

I'm having trouble reading a .txt file to get some data. I want to be able to change some of the values this data contains.
At first, I used this:
A=importdata('myfile.txt');
And got this cell array:
Now what I want is this:
1) Get rid of the headers (the information from cell 1 to 22). That could be easily done by simple indexing (creating a sub-array using just the info from cell 23 to the end of the file).
2) I want to separate the information into different cells, using these identifiers. But I don't know how to separate them into different cells of the array.
'# item bepoch ecode label onset diff dura b_flags a_flags enable bin'
3) Do the same in step 2 to fill those columns with the data in the rest of the cells.
I'm trying to use this approach, but I'm not getting the expected results.
If someone can help me, I'd be glad.
Have you tried dragging the file into the variable workspace window and using the data import wizard? It has some nice features that normally take care of what you are trying to do automatically. Unfortunately, it seems that your text file may have unconventional spacing, but Matlab may be able to handle it if you set the delimeter to ' ' or suchlike.

Easy way to parse file for directives in C?

Is there an easy way to parse a file for a directive (as I can't think of a better word for it)?
I need to scan a file for <!--#directive parameter=value -->, copy the value, find the location and length where this directive was in the file, so it can be replaced with whatever.
I come from microcontrollers, and don't have a lot of experience with extra / full libraries.
Is there a better way to implement this than manually scanning it line by line? (I guess with ftell for position, fgets, and then parse with sscanf, fseek back to last position if it was a match).
Here is a regular expression which can help:
<!--\s*#.+=(\S+)\s?-->
Group with index 1 in each match is your value.
You can test them here: https://regex101.com/
Also consider using high-level language for this. Here is a snippet in C# which prints all values from a text file:
var inputText = File.ReadAllText("D:\\myTextFile.txt");
var regex = new Regex("<!--\\s*#.+=(\\S+)\\s?-->");
var matches = regex.Matches(inputText);
foreach (var g in matches.Cast<Match>().Select(match => match.Groups[1]))
Console.WriteLine(g.ToString());

unterminated string literal error in salesforce

I am trying to get a value from salesforce class into a javascript variable. I am able to get the value if its a single line value, but if its multiline textarea it gives a unterminated string literal error
caseUpdate.Description = "{!ac__c.C_Info__c}";
After googling for sometime i came to know we can have a workaround for this by having a hidden field and using DOM storing it using the document.getElement.Id. But i am calling this code on a button click so i would not be able to create a input text or hidden field value.
Any body who can provide an way to do it?
Thanks
Prady
You should just be able to use the standard Salesforce JSENCODE() function if you are using OnClick Javascript in a button. This will escape any characters for you.
See the documentation.
It is because of line breaks. merge fields are rendered unescaped into the output stream meaning that CRLFs push into a new line and break javascript strings. Either use the div/input trick or use Apex to replace \r\n's in the field with <br/> or whatever best suits the purpose. Also keep in mind that " will also terminate your JS string.
The easiest way is to just include a function in your extension and then you can use it across board
public String FixNewLine(String s) {
if (s != null) return s.replaceAll('\r\n', '<br/>').replaceAll('"', '\\"');
return null;
}
I had the same issue but was able to fix it! The trick is the JSENCODE function. Its basically {!JSENCODE(Obj.Field)}"; So you are replacing your merge field with this function and nesting the merge field itself within the function. In my scenario I ended up with opptyObj.Description="{!JSENCODE(Case.Description)}"; as my total syntax. First calling upon my set object and field, and then the merge data to populate it.

Resources