Thursday, January 19, 2012

Fixed problem for continuous string(long string without space) using regular expression

Last day I have faced a problem for a long string like(adfdsfsdfdsfdsfsdafdsfsdfsdfsdfsdfsdfsdfsdfsdffdsfsdfsdfsdafsdfsdfsdfsdfsdfsdafsdf) which make my application's UI design break. So to fixed this issue I have used regular expression which insert a space after n characters.




To insert a space after every n characters:

var newString = Regex.Replace(oldString, new string('.', n), m => m.Value + " ");

Sample solution:
string longWord = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaassssssssssssssssssssssssdddddddddddddddddddddddddddddaaaaaaaaaafffffffffffffffffffffffffadfdsfsdfdsfdsfsdafdsfsdfsdfsdfsdfsdfsdfsdfsdffdsfsdfsdfsdafsdfsdfsdfsdfsdfsdafsdffdsfdsfdsfsdf";

Regex.Replace(longWord, new string('.', 16), m => m.Value + " ");


In above image it shows that regex place a space after every 16 character for that long string.

No comments:

Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'

Exception: Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'...