Display text in new line textarea in MVC razor - asp.net-mvc

i have a textarea in my mvc application when the user save it for example
hi
how are
you
but when user want to edit that textarea it shows
hi how are you
but i want in that way
hi
how are
you
I have tried
#Html.TextAreaFor(model => model.Notes, new { #class = "form-control", placeholder = "Name", required = "required", #rows = 5 })

To replace each whitespace with a new line character
Edit the ActionResult so that when you save, you replace each " " with Environment.NewLine
like so:
NoteManager.Save(note.Replace(" ", Environment.NewLine));
EDIT
To replace 1st and last space with newline:
// set string
string s = "hi how are you";
// make sure that there are no trailing spaces otherwise our code will not work
s = s.TrimEnd(' ');
// remove 1st space
// get index
int index = s.IndexOf(" ");
// remove space
s = s.Remove(index, 1);
// replace with newline
s = s.Insert(index, Environment.NewLine);
// remove last space
// get index
index = s.LastIndexOf(" ");
// remove space
s = s.Remove(index, 1);
// replace with newline
s = s.Insert(index, Environment.NewLine);
Console.Write(s);
Fiddle: https://dotnetfiddle.net/kg7kcf

Related

Splitting Google Sheets Script?

function doGet(e){
Logger.log("--- doGet ---");
var tag = "",
value = "";
try {
// this helps during debuggin
if (e == null){e={}; e.parameters = {tag:"test",value:"-1"};}
tag = e.parameters.tag;
value = e.parameters.value;
// save the data to spreadsheet
save_data(tag, value);
return ContentService.createTextOutput("Wrote:\n tag: " + tag + "\n value: " + value);
} catch(error) {
Logger.log(error);
return ContentService.createTextOutput("oops...." + error.message
+ "\n" + new Date()
+ "\ntag: " + tag +
+ "\nvalue: " + value);
}
}
// Method to save given data to a sheet
function save_data(tag, value){
Logger.log("--- save_data ---");
try {
var dateTime = new Date();
// Paste the URL of the Google Sheets starting from https thru /edit
// For e.g.: https://docs.google.com/..../edit
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1HYJRHfJVgZp16xYt4fipR1bH2BudhuQ4UrDhAf1rBKw/edit");
var dataLoggerSheet = ss.getSheetByName("Datalogger");
// Get last edited row from DataLogger sheet
var row = dataLoggerSheet.getLastRow() + 1;
// Start Populating the data
dataLoggerSheet.getRange("A" + row).setValue(row -1); // ID
dataLoggerSheet.getRange("B" + row).setValue(dateTime); // dateTime
dataLoggerSheet.getRange("C" + row).setValue(tag); // tag
dataLoggerSheet.getRange("D" + row).setValue(value); // value
//dataLoggerSheet.getRange("E" + row).setValue(value); // value
//dataLoggerSheet.getRange("F" + row).setValue(value); // value
// Update summary sheet
summarySheet.getRange("B1").setValue(dateTime); // Last modified date
// summarySheet.getRange("B2").setValue(row - 1); // Count
}
catch(error) {
Logger.log(JSON.stringify(error));
}
Logger.log("--- save_data end---");
}
In the example above, inside the value of "tag" there is data in the format "12345678912 | ABCDEFGHIJ". "Tag" data in column C; I want to print with the first 11 characters in column D. The "tag" data in column C; I want to print it with column E after 12 characters. How can I do that?
To see my overall objective, these two screenshots should show it.
Original Spreadsheet from Form:
enter image description here
Formatted Version of Spreadsheet:
enter image description here
Thank you in advance for your help.
You will have to manipulate the tag string in order to get the values you want.
In order to do this you will have change this:
dataLoggerSheet.getRange("C" + row).setValue(tag); // tag
To this:
dataLoggerSheet.getRange("C" + row).setValue(tag.slice(0,tag.indexOf('|')); //first part of tag
dataLoggerSheet.getRange("D" + row).setValue(tag.slice(tag.indexOf('|') + 2)); // second part of tag
dataLoggerSheet.getRange("E" + row).setValue(value); // value
Explanation
The above snippet makes use of the indexOf and slice methods from JavaScript in order to get the index of the | character in order to be able to split the tag string into two different strings.
Reference
JavaScript Array.prototype.slice();
JavaScript Array.prototype.indexOf().

How to Add extra Arabic letters in Browse pages (in Mirage2 theme of dspace-6.0)

I tried to add Arabic letters at the Browse page by using the below code but i did not succeeded,the Arabic Letters were not appearing at the Browse page.
The code which i tried is as below:-
else
{
// Create a clickable list of the alphabet
List jumpList = jump.addList("jump-list", List.TYPE_SIMPLE, "alphabet");
// browse params for each letter are all the query params
// WITHOUT the second-stage browse value, and add STARTS_WITH.
Map<String, String> letterQuery = new HashMap<String, String>(queryParamsGET);
for (String valueKey : BrowseParams.FILTER_VALUE)
{
letterQuery.remove(valueKey);
}
letterQuery.put(BrowseParams.STARTS_WITH, "0");
jumpList.addItemXref(super.generateURL(BROWSE_URL_BASE, letterQuery), "0-9");
for (char c = 'A'; c <= 'Z'; c++)
{
letterQuery.put(BrowseParams.STARTS_WITH, Character.toString(c));
jumpList.addItemXref(super.generateURL(BROWSE_URL_BASE, letterQuery), Character
.toString(c));
}
//I HAVE ADDED BELOW CODE TO CREATE A BROWSE LIST FOR ARABIC TEXT
// I HAVE CREATED A LIST FOR ARABIC CHARACTERS
List jumpList2 = jump.addList("jump-list2", List.TYPE_SIMPLE, "alphabet");
// I HAVE CREATED A HASHMAP FOR ARABIC CHARACTERS
Map<String, String> ddQuery = new HashMap<String, String>(queryParamsGET);
for (String valueKey : BrowseParams.FILTER_VALUE)
{
ddQuery.remove(valueKey);
}
//I HAVE ADDED BELOW CODE TO CREATE A BROWSE LIST FOR ARABIC TEXT
for (char d = 'ا'; d <= 'ى'; d++)
{
ddQuery.put(BrowseParams.STARTS_WITH, Character.toString(d));
jumpList2.addItemXref(super.generateURL(BROWSE_URL_BASE, ddQuery), Character
.toString(d));
}
I do it with javascript because i cant rebuild dspace.
window.addEventListener('DOMContentLoaded', function(event){
var elem = jQuery('ul.alphabet.list-inline li:first-child').clone()
if (elem.length){
jQuery('ul.alphabet.list-inline').append('<br>')
var href = elem.children('a').attr('href');
var str = 'ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی'
for (var i = 0; i != str.length ; i++){
var c = str.charAt(i)
elem.children('a').text(c)
elem.children('a').attr('href',href.replace('starts_with=0','starts_with='+c));
jQuery('ul.alphabet.list-inline').append(elem.clone())
jQuery('ul.alphabet.list-inline').append(' ')
}
}
});

asp.net mvc razor string with double quotes

I am trying to use a string with double quotes but unable to get it work
#{
string disableMessage = "";
var disableAttr = "";
if (ViewBag.IsApplicable)
{
disableMessage = "You dont have permission to add new Item.";
disableAttr = "class=" + "disableItem" +" title="+"\""+ disableMessage +"\"";
}
}
expected: disableAttr as
class=disableItem title="You dont have permission to add new demand."
I got struck at getting double quotes for title attribute.
Why not deal with the two attributes separately:
#{
string disableTitle = null;
string disableClass = null;
if (ViewBag.IsApplicable)
{
disableTitle = "You dont have permission to add new Item.";
disableClass = "disableItem";
}
}
<div class="#disableClass" title="#disableTitle">Content</div>
Note that Razor V2 (in MVC4+) has a "conditional attribute" feature. When an attribute value is null, then Razor won't output anything at all for the attribute. So in the example above, if ViewBag.IsApplicable is false, the output will be:
<div>Content</div>
Ross's answer is much more elegant. However, keeping the line of your original code, you could do the following:
disableAttr = "class='disableItem'" +" title='"+ disableMessage +"'";
This will render the following text inside disableAttr:
class='disableItem' title='your_message_here';

How to convert integer to text for usage in textfield java-blackberry

I want to use an integer value in a TextField. In the below code I am retrieving integer value from table into textfield3. When I use getInteger(2) it is giving error. So what would be the alternative. If parsing is the solution (e.g. .toString) how is it to be implemented in this approach?
TextField3 = new TextField("Amount: ",r.getString(2));
add(TextField3);
This is what I am exactly trying to do
try
{
//Open or create the database
Database db = DatabaseFactory.openOrCreate("database1.db");
//Retrieval
Statement statement1 = db.createStatement("SELECT date,name,amount,narration FROM Bills where id='"+TextField00.getText()+"'");
//This is one text field to accept id value
statement1.prepare();
statement1.execute();
Cursor c = statement1.getCursor();
Row r;
while(c.next())
{
r = c.getRow();
TextField5 = new TextField("Date: ",r.getString(0));
add(TextField5);
TextField2 = new TextField("Customer Name: ",r.getString(1));
add(TextField2);
TextField3 = new TextField("Amount: ",r.getString(2));
add(TextField3);
TextField4 = new TextField("Narration: ",r.getString(3));
add(TextField4);
}
//statement1.prepare();
//statement1.execute();
statement1.close();
db.close();
}
catch( Exception e )
{
System.out.println( e.getMessage() );
e.printStackTrace();
}
Hope it aids your understanding.
Try this line,
TextField3 = new TextField("Amount: ", r.getInteger(2) + "");
Instead of
TextField3 = new TextField("Amount: ",r.getString(2));
You can use java.lang.Integer.toString():
TextField3 = new TextField("Amount: ", Integer.toString(r.getInteger(2)));

cannot preserve space between runs

i want to generate a word document
as an input i have this string "open packaging conventions" and each word will have a different style
the result should be open packaging conventions
WordprocessingDocument document = WordprocessingDocument.Create(
#"C:\test PFE.docx",
WordprocessingDocumentType.Document
);
MainDocumentPart mainDocumentPart = document.AddMainDocumentPart();
mainDocumentPart.Document = new Document();
mainDocumentPart.Document.AddNamespaceDeclaration("ve", "http://schemas.openxmlformats.org/markup-compatibility/2006");
mainDocumentPart.Document.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
mainDocumentPart.Document.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
mainDocumentPart.Document.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
mainDocumentPart.Document.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
mainDocumentPart.Document.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
mainDocumentPart.Document.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
mainDocumentPart.Document.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
mainDocumentPart.Document.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
Body documentBody = new Body();
mainDocumentPart.Document.Append(documentBody);
StyleDefinitionsPart styleDefinitionsPart =
mainDocumentPart.AddNewPart<StyleDefinitionsPart>();
FileStream stylesTemplate =
new FileStream("styles.xml", FileMode.Open, FileAccess.Read);
styleDefinitionsPart.FeedData(stylesTemplate);
styleDefinitionsPart.Styles.Save();
#region Titre du document
Paragraph titleParagraphe = new Paragraph() { RsidParagraphAddition = "00AF4948", RsidParagraphProperties = "00625634", RsidRunAdditionDefault = "00625634" }; ;
Run run = new Run();
RunProperties rpr = new RunProperties();
RunStyle rstylr = new RunStyle { Val = "style1" };
run.Append(rpr);
Text t = new Text("open");
run.Append(t);
titleParagraphe.Append(run);
run = new Run();
rpr = new RunProperties();
rstylr = new RunStyle { Val = "style2" };
run.Append(rpr);
t = new Text("packaging")
{
Space = new DocumentFormat.OpenXml.EnumValue<DocumentFormat.OpenXml.SpaceProcessingModeValues> { InnerText = "preserve" }
};
run.Append(t);
titleParagraphe.Append(run);
run = new Run();
rpr = new RunProperties();
rstylr = new RunStyle { Val = "style1" };
run.Append(rpr);
t = new Text("conventions")
{
Space = new DocumentFormat.OpenXml.EnumValue<DocumentFormat.OpenXml.SpaceProcessingModeValues> { InnerText = "preserve" }
};
run.Append(t);
titleParagraphe.Append(run);
documentBody.Append(titleParagraphe);
document.MainDocumentPart.Document.Save();
document.Dispose();
and the result is open*packaging*conventions without space between words
can some one help me please?!
You're on good way by handling the Space property, but you need to do it like this:
t = new Text()
{
Text = "your text with spaces ",
Space = SpaceProcessingModeValues.Preserve
};
Here is another way to set the attribute Space that can be used to specify SpaceProcessingMode.
t = new Text("This is some text");
t.Space = SpaceProcessingModeValues.Preserve;
The default of the attribute is SpaceProcessingModeValues.Default.
From API Documentation:
<w:r>
<w:t> significant whitespace </w:t>
</w:r>
Although there are three spaces on each side of the text content in the run, that whitespace has not been specifically marked as significant, therefore it is subject to the space preservation rules currently specified in that run's scope. end example]
The possible values for this attribute are defined by §2.10 of the XML 1.0 specification.

Resources