I have the following file path displaying:
And I want to display only file name 'Doc1' (minus path and extension).
I have tried unsucessfully the following and would appreciate any further light you could share as to what I am doing wrong...
@functions{
public static string SplitWord(string text, int length)
{
string str = text;
int n = str.LastIndexOf(".");
string str1=str.Substring(n,str.LastIndexOf("/"));
str1=str1.Substring(1,str1.Length);
return str1;
}
}
<ol>
@foreach (var q in AsDynamic(App.Data["CatFilter"]))
{
<li class="sc-element faq-set faq-setOne" data-tags="@String.Join(",", ((List<DynamicEntity>)q.Categories).Select(a => AsDynamic(a).EntityId))">
@q.Toolbar @Edit.Toolbar(actions: "edit,new", contentType: "CatFilter")
<a class="faq-question" style="cursor: pointer">
@if(!String.IsNullOrEmpty(q.LinkText))
{
SplitWord(@q.LinkText,@q.LinkText.Length);
} else {
SplitWord(@q.Link,@q.Link.Length);
}
</a>
</li>
}
</ol>
I have also tried variations of the following within the IF condition but again no luck.
,,,,@:var str = q.Link;
,,,,@:var n = str.lastIndexOf(".");
,,,,@:var str1=str.Substring(n,str.lastIndexOf("/"))
,,,,@:str1=str1.Substring(1,str1.Length);
Thx,
You're actually just using Substring the wrong way. You probably want
Give it a try - might need another +1 or -1 on one of the values, but that should do the trick.
You were right (with a minor tweak as you said)....
I also tried to integrate a date field so no matter what date a user selects, it will always display current date (of upload).
Is there a string to enter into the default value for datepicker field to display 'Today' as opposed to user having to click it in picker? (mixing questions again :) )
UPDATE
This is another template of yours that I applied the SplitWord function to but results in an error. I can't see any difference from code which works fine above.
This is the code I'm referring to: