我有一个很长的字符串,当我发现由ALTER PROCEDURE [dbo].[Reports_UnDisbursedSalaryReport]
(
@FromDate SMALLDATETIME,
@ToDate SMALLDATETIME,
@OfficeID INT = 3,
@Type INT = 1,
@EmployerUniqueID VARCHAR(15) = '',
@EmployeeUniqueID VARCHAR(15) = ''
)
AS
BEGIN
SET @EmployerUniqueID =
CASE
WHEN LEN(@EmployerUniqueID) <=0
THEN NULL
ELSE @EmployerUniqueID
END
SET @EmployeeUniqueID =
CASE
WHEN LEN(@EmployeeUniqueID) <= 0
THEN NULL
ELSE @EmployeeUniqueID
END
DECLARE @Branches TABLE (BranchID INT)
IF @Type = 1
BEGIN
INSERT INTO @Branches
SELECT BranchID
FROM vw_OrganizationTree
WHERE OrganizationID = @OfficeID
END
IF @Type = 2
BEGIN
INSERT INTO @Branches
SELECT BranchID
FROM vw_OrganizationTree
WHERE CompanyID = @OfficeID
END
IF @Type = 3
BEGIN
INSERT INTO @Branches
SELECT BranchID
FROM vw_OrganizationTree
WHERE BranchID = @OfficeID
END
SELECT
DATEADD(HOUR, 4, PF.EntryDateTime) 'EntryDateTime',
C.CompanyName, B.BranchName,
@FromDate as 'Fromdate', @ToDate as 'Todate',
E.EmployerName, RE.EmployeeName, RE.EmployeeUniqueID,
FE.IncomeFixedComponent, FE.IncomeVariableComponent,
S.StatusDescription
FROM
File_EdrEntries FE
JOIN
RegisteredEmployees RE ON RE.EmployeeUniqueID = FE.EmployeeUniqueID
JOIN
Employers E ON E.ID = RE.Employer_ID
JOIN
Branches B ON B.BranchID = E.Branch_ID
JOIN
companies C ON C.COMPANYID = B.COMPANY_ID
JOIN
Statuses S ON S.StatusID = FE.Status_ID
JOIN
PAFFiles PF ON PF.ID = FE.PAFFile_ID
WHERE
PF.EntryDateTime >= @FromDate
AND PF.EntryDateTime < DATEADD(DAY, 1, @ToDate)
AND Status_ID IN (1, 2)
AND E.Branch_id IN (SELECT BranchID From @Branches)
AND CAST(E.EmployerID AS BIGINT) = ISNULL(CAST(@EmployerUniqueID AS BIGINT), CAST(E.EmployerID AS BIGINT))
AND CAST(RE.EmployeeUniqueID AS BIGINT) = ISNULL(CAST(@EmployeeUniqueID AS BIGINT), CAST(RE.EmployeeUniqueID AS BIGINT))
END
组成的三个字符的序列时,我将用0x0d 0x0a 0x20
替换这三个字符。
问题是我在下面的第一个if子句中0x5c 0x6e 0x20
之后没有匹配。
0x0d 0x0a 0x20
//托尼
答案 0 :(得分:1)
字符串是不可变的,因此您需要将其分配给新的字符串。
如果我说得对,你可以使用常规字符串方法替换将allTest字符串中0x0d 0x0a 0x20
的所有实例更改为0x5c 0x6e 0x20
。
string textThatShouldBeReplaced = @"0x0d 0x0a 0x20";
string textToReplace = @"0x5c 0x6e 0x20";
if (allText.IndexOf(@"\r\n ") != -1)
{
if( allText.IndexOf(@"\n ") != -1)
{
allText = allText.Replace(textThatShouldBeReplaced,textToReplace);
}
}