Skip to main content
Code Review

Return to Question

meaningful title
Link
Caridorc
  • 28.1k
  • 7
  • 54
  • 137

Plese review following methods Comment formatter

private string FormatComments(string comments)
{
 //If comments has no space and inserted as a single line then following code will break
 //the comments into multiple lines.
 StringBuilder sb = new StringBuilder();
 int c = 65;
 int l = comments.Length;
 if (l < c)
 return comments;
 int r = l % c;
 int lines = (l - r) / c;
 
 if (lines == 0)
 return comments;
 int index = 0;
 for (int i = 0; i < lines; i++)
 {
 if (index > comments.Length)
 break;
 string indexVal = comments[index + c].ToString();
 sb = sb.AppendLine(comments.Substring(index, c) + (indexVal == " " ? "" : "- "));
 index = index + c;
 }
 if(r > 0)
 sb = sb.AppendLine(comments.Substring(index, r));
 
 return sb.ToString();
}
--------------------------------------------------------------------------------------------------------

private void SaveValuesInViewState()
{
 string[] roomStr = this.RoomsString.Split('~');
 List<Room> rooms = new List<Room>();
 Room room = null;
 foreach (string str in roomStr)
 {
 room = new Room();
 string[] vals = str.Split('|');
 // 
 room.NoOfRooms = Convert.ToInt32(vals[0]);
 room.Type = (RoomType)Enum.Parse(typeof(RoomType), vals[1]);
 room.NumberOfCots = Convert.ToInt32(vals[2]);
 string[] childInfo = vals[3].Split('^');
 if (Convert.ToInt32(childInfo[0]) > 0)
 {
 foreach (string age in childInfo[1].Split(','))
 {
 room.ChildrenAges.Add(Convert.ToInt32(age));
 }
 }
 rooms.Add(room);
 }
 this.Rooms = rooms;
}
private string FormatComments(string comments)
{
 //If comments has no space and inserted as a single line then following code will break
 //the comments into multiple lines.
 StringBuilder sb = new StringBuilder();
 int c = 65;
 int l = comments.Length;
 if (l < c)
 return comments;
 int r = l % c;
 int lines = (l - r) / c;
 
 if (lines == 0)
 return comments;
 int index = 0;
 for (int i = 0; i < lines; i++)
 {
 if (index > comments.Length)
 break;
 string indexVal = comments[index + c].ToString();
 sb = sb.AppendLine(comments.Substring(index, c) + (indexVal == " " ? "" : "- "));
 index = index + c;
 }
 if(r > 0)
 sb = sb.AppendLine(comments.Substring(index, r));
 
 return sb.ToString();
}
--------------------------------------------------------------------------------------------------------
private void SaveValuesInViewState()
{
 string[] roomStr = this.RoomsString.Split('~');
 List<Room> rooms = new List<Room>();
 Room room = null;
 foreach (string str in roomStr)
 {
 room = new Room();
 string[] vals = str.Split('|');
 // 
 room.NoOfRooms = Convert.ToInt32(vals[0]);
 room.Type = (RoomType)Enum.Parse(typeof(RoomType), vals[1]);
 room.NumberOfCots = Convert.ToInt32(vals[2]);
 string[] childInfo = vals[3].Split('^');
 if (Convert.ToInt32(childInfo[0]) > 0)
 {
 foreach (string age in childInfo[1].Split(','))
 {
 room.ChildrenAges.Add(Convert.ToInt32(age));
 }
 }
 rooms.Add(room);
 }
 this.Rooms = rooms;
}
private string FormatComments(string comments)
{
 //If comments has no space and inserted as a single line then following code will break
 //the comments into multiple lines.
 StringBuilder sb = new StringBuilder();
 int c = 65;
 int l = comments.Length;
 if (l < c)
 return comments;
 int r = l % c;
 int lines = (l - r) / c;
 
 if (lines == 0)
 return comments;
 int index = 0;
 for (int i = 0; i < lines; i++)
 {
 if (index > comments.Length)
 break;
 string indexVal = comments[index + c].ToString();
 sb = sb.AppendLine(comments.Substring(index, c) + (indexVal == " " ? "" : "- "));
 index = index + c;
 }
 if(r > 0)
 sb = sb.AppendLine(comments.Substring(index, r));
 
 return sb.ToString();
}

private void SaveValuesInViewState()
{
 string[] roomStr = this.RoomsString.Split('~');
 List<Room> rooms = new List<Room>();
 Room room = null;
 foreach (string str in roomStr)
 {
 room = new Room();
 string[] vals = str.Split('|');
 // 
 room.NoOfRooms = Convert.ToInt32(vals[0]);
 room.Type = (RoomType)Enum.Parse(typeof(RoomType), vals[1]);
 room.NumberOfCots = Convert.ToInt32(vals[2]);
 string[] childInfo = vals[3].Split('^');
 if (Convert.ToInt32(childInfo[0]) > 0)
 {
 foreach (string age in childInfo[1].Split(','))
 {
 room.ChildrenAges.Add(Convert.ToInt32(age));
 }
 }
 rooms.Add(room);
 }
 this.Rooms = rooms;
}
Tweeted twitter.com/#!/StackCodeReview/status/70005789246488577
Source Link
Kashif
  • 399
  • 1
  • 4
  • 7

Plese review following methods

private string FormatComments(string comments)
{
 //If comments has no space and inserted as a single line then following code will break
 //the comments into multiple lines.
 StringBuilder sb = new StringBuilder();
 int c = 65;
 int l = comments.Length;
 if (l < c)
 return comments;
 int r = l % c;
 int lines = (l - r) / c;
 
 if (lines == 0)
 return comments;
 int index = 0;
 for (int i = 0; i < lines; i++)
 {
 if (index > comments.Length)
 break;
 string indexVal = comments[index + c].ToString();
 sb = sb.AppendLine(comments.Substring(index, c) + (indexVal == " " ? "" : "- "));
 index = index + c;
 }
 if(r > 0)
 sb = sb.AppendLine(comments.Substring(index, r));
 
 return sb.ToString();
}
--------------------------------------------------------------------------------------------------------
private void SaveValuesInViewState()
{
 string[] roomStr = this.RoomsString.Split('~');
 List<Room> rooms = new List<Room>();
 Room room = null;
 foreach (string str in roomStr)
 {
 room = new Room();
 string[] vals = str.Split('|');
 // 
 room.NoOfRooms = Convert.ToInt32(vals[0]);
 room.Type = (RoomType)Enum.Parse(typeof(RoomType), vals[1]);
 room.NumberOfCots = Convert.ToInt32(vals[2]);
 string[] childInfo = vals[3].Split('^');
 if (Convert.ToInt32(childInfo[0]) > 0)
 {
 foreach (string age in childInfo[1].Split(','))
 {
 room.ChildrenAges.Add(Convert.ToInt32(age));
 }
 }
 rooms.Add(room);
 }
 this.Rooms = rooms;
}
lang-cs

AltStyle によって変換されたページ (->オリジナル) /